Is this number a hill number?











up vote
17
down vote

favorite
2












A hill number is a number that has the same digit in the first & the last, but that's not all. In a hill number the first digits are strictly increasing, and the last digits are strictly decreasing. The largest digit can be repeated.



Here is an example of a hill number:



12377731 | 1237...             | ...731
^ same ^ | strictly increasing | strictly decreasing
---------+---------------------+---------------------
12377731
^^^ okay because largest digit can be repeated


This is not:



4588774 | ...8774
| ^^ not the largest digit
| so this has to be strictly decreasing
| but it's not, so not a hill number


Challenge



Given a positive integer, write a full program or a function that returns truthy for hill numbers but falsy on other values.



Notes:




  • Input & output can be in any reasonable format.

  • This is code-golf so shortest answer in each language wins!


Test Cases



12321 -> Truthy
1233321 -> Truthy
99 -> Truthy
3 -> Truthy
234567992 -> Truthy
1232 -> Falsy
778896 -> Falsy
23232 -> Falsy
45566554 -> Falsy
5645 -> Falsy









share|improve this question




















  • 5




    What about 222222222? Is it a flat hill number?
    – frarugi87
    Nov 19 at 14:56






  • 1




    222222222 is a hill number, largest digit is 2 and thus can be repeated
    – u_ndefined
    Nov 20 at 13:02








  • 1




    Is a string reasonable?
    – Sanchises
    Nov 20 at 13:11










  • @frarugi87 See comment above.
    – Dennis
    Nov 20 at 13:27










  • Is 1230321 a hill number?
    – HelloGoodbye
    2 days ago















up vote
17
down vote

favorite
2












A hill number is a number that has the same digit in the first & the last, but that's not all. In a hill number the first digits are strictly increasing, and the last digits are strictly decreasing. The largest digit can be repeated.



Here is an example of a hill number:



12377731 | 1237...             | ...731
^ same ^ | strictly increasing | strictly decreasing
---------+---------------------+---------------------
12377731
^^^ okay because largest digit can be repeated


This is not:



4588774 | ...8774
| ^^ not the largest digit
| so this has to be strictly decreasing
| but it's not, so not a hill number


Challenge



Given a positive integer, write a full program or a function that returns truthy for hill numbers but falsy on other values.



Notes:




  • Input & output can be in any reasonable format.

  • This is code-golf so shortest answer in each language wins!


Test Cases



12321 -> Truthy
1233321 -> Truthy
99 -> Truthy
3 -> Truthy
234567992 -> Truthy
1232 -> Falsy
778896 -> Falsy
23232 -> Falsy
45566554 -> Falsy
5645 -> Falsy









share|improve this question




















  • 5




    What about 222222222? Is it a flat hill number?
    – frarugi87
    Nov 19 at 14:56






  • 1




    222222222 is a hill number, largest digit is 2 and thus can be repeated
    – u_ndefined
    Nov 20 at 13:02








  • 1




    Is a string reasonable?
    – Sanchises
    Nov 20 at 13:11










  • @frarugi87 See comment above.
    – Dennis
    Nov 20 at 13:27










  • Is 1230321 a hill number?
    – HelloGoodbye
    2 days ago













up vote
17
down vote

favorite
2









up vote
17
down vote

favorite
2






2





A hill number is a number that has the same digit in the first & the last, but that's not all. In a hill number the first digits are strictly increasing, and the last digits are strictly decreasing. The largest digit can be repeated.



Here is an example of a hill number:



12377731 | 1237...             | ...731
^ same ^ | strictly increasing | strictly decreasing
---------+---------------------+---------------------
12377731
^^^ okay because largest digit can be repeated


This is not:



4588774 | ...8774
| ^^ not the largest digit
| so this has to be strictly decreasing
| but it's not, so not a hill number


Challenge



Given a positive integer, write a full program or a function that returns truthy for hill numbers but falsy on other values.



Notes:




  • Input & output can be in any reasonable format.

  • This is code-golf so shortest answer in each language wins!


Test Cases



12321 -> Truthy
1233321 -> Truthy
99 -> Truthy
3 -> Truthy
234567992 -> Truthy
1232 -> Falsy
778896 -> Falsy
23232 -> Falsy
45566554 -> Falsy
5645 -> Falsy









share|improve this question















A hill number is a number that has the same digit in the first & the last, but that's not all. In a hill number the first digits are strictly increasing, and the last digits are strictly decreasing. The largest digit can be repeated.



Here is an example of a hill number:



12377731 | 1237...             | ...731
^ same ^ | strictly increasing | strictly decreasing
---------+---------------------+---------------------
12377731
^^^ okay because largest digit can be repeated


This is not:



4588774 | ...8774
| ^^ not the largest digit
| so this has to be strictly decreasing
| but it's not, so not a hill number


Challenge



Given a positive integer, write a full program or a function that returns truthy for hill numbers but falsy on other values.



Notes:




  • Input & output can be in any reasonable format.

  • This is code-golf so shortest answer in each language wins!


Test Cases



12321 -> Truthy
1233321 -> Truthy
99 -> Truthy
3 -> Truthy
234567992 -> Truthy
1232 -> Falsy
778896 -> Falsy
23232 -> Falsy
45566554 -> Falsy
5645 -> Falsy






code-golf decision-problem number-theory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 18 hours ago

























asked Nov 19 at 10:56









u_ndefined

604113




604113








  • 5




    What about 222222222? Is it a flat hill number?
    – frarugi87
    Nov 19 at 14:56






  • 1




    222222222 is a hill number, largest digit is 2 and thus can be repeated
    – u_ndefined
    Nov 20 at 13:02








  • 1




    Is a string reasonable?
    – Sanchises
    Nov 20 at 13:11










  • @frarugi87 See comment above.
    – Dennis
    Nov 20 at 13:27










  • Is 1230321 a hill number?
    – HelloGoodbye
    2 days ago














  • 5




    What about 222222222? Is it a flat hill number?
    – frarugi87
    Nov 19 at 14:56






  • 1




    222222222 is a hill number, largest digit is 2 and thus can be repeated
    – u_ndefined
    Nov 20 at 13:02








  • 1




    Is a string reasonable?
    – Sanchises
    Nov 20 at 13:11










  • @frarugi87 See comment above.
    – Dennis
    Nov 20 at 13:27










  • Is 1230321 a hill number?
    – HelloGoodbye
    2 days ago








5




5




What about 222222222? Is it a flat hill number?
– frarugi87
Nov 19 at 14:56




What about 222222222? Is it a flat hill number?
– frarugi87
Nov 19 at 14:56




1




1




222222222 is a hill number, largest digit is 2 and thus can be repeated
– u_ndefined
Nov 20 at 13:02






222222222 is a hill number, largest digit is 2 and thus can be repeated
– u_ndefined
Nov 20 at 13:02






1




1




Is a string reasonable?
– Sanchises
Nov 20 at 13:11




Is a string reasonable?
– Sanchises
Nov 20 at 13:11












@frarugi87 See comment above.
– Dennis
Nov 20 at 13:27




@frarugi87 See comment above.
– Dennis
Nov 20 at 13:27












Is 1230321 a hill number?
– HelloGoodbye
2 days ago




Is 1230321 a hill number?
– HelloGoodbye
2 days ago










19 Answers
19






active

oldest

votes

















up vote
9
down vote














Jelly, 8 bytes



_ƝṠÞ+SƊƑ


Try it online!



How it works



_ƝṠÞ+SƊƑ  Main link. Argument: n (integer)

_Ɲ Take the differences of neighboring digits.
This maps n = abcd to [a-b, b-c, c-d].
Ƒ Fixed; apply the link to the left and return 1 if the result is equal to
its argument, 0 if not.
Ɗ Drei; combine the three links to the left into a monadic chain.
ṠÞ Sort the differences by their signs (negative, zero, positive).
S Take the sum of the differences, yielding 0 if and only if the
first digit is equal to the last.
+ Add the sum to each difference.





share|improve this answer






























    up vote
    6
    down vote













    JavaScript (ES6), 62 54 bytes



    Takes input as a string. Returns a Boolean value.



    s=>s[-[...s].some(p=q=n=>q>(q=Math.sign(p-(p=n))))]==p


    Try it online!



    Commented



    s =>                  // s = input string
    s[ // we will eventually access either s[0] or s[-1]
    -[...s].some( // depending on the result of this some()
    p = q = // initialize p and q to non-numeric values
    n => // for each digit n:
    q > ( // compare q with
    q = // the new value of q,
    Math.sign( // defined as the sign of
    p - (p = n) // the difference between the current digit and the previous one
    )) // yield true if the previous q is greater than the new q
    ) // s[-1] being undefined, a truhty some() will force the test to fail
    ] == p // otherwise: test if the 1st digit s[0] is equal to the last digit p




    JavaScript (ES6), 65 bytes



    A solution using a regular expression. Takes input as a string. Returns $0$ or $1$.



    s=>/N(,-d+)*(,0)*[^0-]*$/.test([...s].map(p=v=>p-(p=v)))&p==s[0]


    Try it online!



    How?



    We first convert the number to a list of pairwise digit differences in $[-9,9]$:



    [...s].map(p = v => p - (p = v))


    Example:



    "234567992" --> [ NaN, -1, -1, -1, -1, -1, -2, 0, 7 ]


    This array is coerced to a string, which gives:



    "NaN,-1,-1,-1,-1,-1,-2,0,7"


    We apply the following regular expression:



     +-----------------------> the second 'N' of 'NaN'
    | +------------------> a sequence of negative numbers
    | | +------------> a sequence of zeros
    | | | +------> a sequence of positive numbers
    | | | | +---> end of string
    | | | | |
    |/¨¨¨¨¨¨/¨¨¨/¨¨¨¨|
    /N(,-d+)*(,0)*[^0-]*$/


    Finally, we also test if the last digit p is equal to the first digit s[0].






    share|improve this answer























    • You can save 5 bytes by taking input as an array of digits.
      – Shaggy
      Nov 19 at 19:11










    • @Shaggy I wish I could but this is apparently not allowed .
      – Arnauld
      Nov 19 at 19:25










    • From the spec, with original emphasis: "Input & output can be in any reasonable format" - we usually consider a digit array a reasonable format for an integer.
      – Shaggy
      Nov 19 at 19:47


















    up vote
    4
    down vote













    Pyth, 16 bytes



    &SI_._MJ.+jQT!sJ


    Try the test suite.



              jQT          input in base 10
    J.+ J = differences: [3,1,4,1] -> [-2,3,-3]
    ._M Signs of each element of J
    _ Reverse the list
    SI and check if it is Invariant under Sorting.
    If this is true, J consists of some positive numbers,
    followed by some 0s, followed by some negative numbers,
    which is what we want.
    !sJ Now we check the other hill condition by ensuring
    sum(differences) = 0; i.e. the first and last digit are equal.
    & We take the logical AND of both conditions.





    share|improve this answer




























      up vote
      4
      down vote














      Jelly, 11 bytes



      DIµṠNṢƑaS¬$


      Explanation:



      D               Convert to a list of Digits.
      I Increments; compute differences between successive elements.
      µ Start new µonadic link.
      Ṡ Find Ṡign of each increment
      N then negate;
      ṢƑ is the result invariant under Ṣorting?
      If so, the increments consist of some positive numbers,
      followed by some 0s, followed by some negative numbers,
      which is what we want.
      a Logical AND this result with
      S¬$ logical NOT of the Sum of the increments.
      If the sum of the increments is zero, first and last digits are equal.


      Try it online!






      share|improve this answer






























        up vote
        4
        down vote














        Perl 6, 39 bytes





        {.[0]==.tail&&[<=] $_ Z<=>.skip}o*.comb


        Try it online!



        Explanation



        { ... }o.comb  # Split into digits and feed into block
        .[0]==.tail # First element equals last
        && # and
        $_ Z<=>.skip # Pairwise application of three-way comparator
        [<=] # Results never decrease





        share|improve this answer





















        • I was literally seconds away from posting this lol.
          – Jo King
          Nov 19 at 12:41


















        up vote
        3
        down vote














        Python 2, 114 112 bytes





        lambda n:all((n[0]==n[-1])*sorted(set(x))==list(x)[::d]for x,d in zip(n.split(max(n)*n.count(max(n)),1),[1,-1]))


        Try it online!






        share|improve this answer




























          up vote
          3
          down vote














          R, 65 bytes



          Takes strings. Took the idea for checking sort invariance from the Pyth answer.





          function(a)!sum(d<-diff(utf8ToInt(a)))&all(sort(k<-sign(d),T)==k)


          Try it online!






          share|improve this answer






























            up vote
            2
            down vote














            05AB1E, 19 17 13 12 bytes



            ¥D.±Â{RQsO_*


            -5 bytes by creating a port of @lirtosiast's Pyth answer.



            Try it online or verify all test cases.



            Explanation:





            ¥           # Push the deltas of the digits of the (implicit) input
            # i.e. 4588774 → [1,3,0,-1,0,-3]
            D # Duplicate this list
            .± # Get the sign of each
            # [1,3,0,-1,0,-3] → [1,1,0,-1,0,-1]
            Â # Bifurcate (short for DR: Duplicate and Reverse copy)
            # i.e. [1,1,0,-1,0,-1] → [-1,0,-1,0,1,1]
            { # Sort the copy
            # i.e. [-1,0,-1,0,1,1] → [-1,-1,0,0,1,1]
            R # Reverse it
            # i.e. [1,1,0,0,-1,-1]
            Q # And check if they are equal
            # i.e. [1,1,0,-1,0,-1] and [1,1,0,0,-1,-1] → 0 (falsey)
            s # Swap to get the list of deltas again
            O # Take the sum
            # i.e. [1,3,0,-1,0,-3] → 0
            _ # And check if it's exactly 0
            # 0 → 1 (truthy)
            * # Check if both are truthy (and output implicitly)
            # i.e. 0 and 1 → 0 (falsey)


            Â{RQ can alternatively be (Â{Q for the same byte-count, where ( negates each sign: Try it online.






            share|improve this answer






























              up vote
              2
              down vote













              J, 23 bytes



              [:((0=+/)**-:*/:*)2-/]


              Idea stolen from the Jelly answers. Just wanted to see how short I could make it in J.



              Try it online!






              share|improve this answer






























                up vote
                2
                down vote














                MATL, 12 bytes



                dZSd1<AGds~*


                Try it online!



                Explanation



                Input is a string of digits. Output is a 1 or 0. The number 222222 is a hill number according to this program. Saved 2 bytes by copying Dennis' method for checking equality of the first and last digits.



                d               % Takes the difference between digits
                ZS % Calculate the sign.
                d % Take the difference again.
                1< % A number is a hill number if these differences are < 1.
                A % Truthy iff above is all true OR if array is empty (necessary for short inputs)
                Gds % Push the input, and sum all the differences.
                ~ % Negate
                * % Multiply the two tests (=logical AND).





                share|improve this answer






























                  up vote
                  1
                  down vote













                  Japt, 11 bytes



                  Takes input as a digit array.



                  ä-
                  eUñg)«Ux


                  Try it or run all test cases






                  share|improve this answer




























                    up vote
                    1
                    down vote














                    Python 2, 53 bytes





                    def f(s):x=map(cmp,s,s[1:]);s[:sorted(x)==x]!=s[-1]>_


                    Takes input as a string. Output is via presence or absence of an exception.



                    Try it online!






                    Python 2, 62 bytes





                    lambda s:s[:eval('<='.join(map(str,map(cmp,s,s[1:]))))]==s[-1]


                    Takes input as a string and returns a Boolean.



                    Try it online!






                    share|improve this answer























                    • Whoa, I've been hurting my head for hours and I couldn't even come up with something shorter than the combined byte count of your 2 solutions ! Cheers.
                      – etene
                      Nov 20 at 17:01


















                    up vote
                    1
                    down vote













                    Mathematica/Wolfram Language, 69 64 bytes



                    Pure function. Takes input as an integer, returns True or False.



                    Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&


                    Explanation:



                    The first clause checks the "hilliness":





                    • IntegerDigits: Get digits from integer. Store in y.


                    • -Differences: Take successive differences and flip signs.


                    • Sign: Replace each entry with +1 if positive, 0 if zero, and -1 if negative. Store in x.


                    • Sort: Sort list of +1, 0, -1 from smallest to largest. Compare to original list in x.


                    The second clause checks whether the first and last digits are equal.



                    A tip of the hat to @IanMiller for tips on refining this code.






                    share|improve this answer























                    • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                      – Michael Seifert
                      Nov 19 at 18:58












                    • Can save 5 bytes with the following changes: Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&
                      – Ian Miller
                      16 hours ago




















                    up vote
                    0
                    down vote














                    Retina 0.8.2, 52 bytes



                    .
                    $*1;$&$*1,
                    (1+),1
                    ,
                    ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                    Try it online! Link includes test cases. Explanation:



                    .
                    $*1;$&$*1,


                    Convert each digit to unary twice, separated by ;s and terminated by ,s. However, you can then think of the result as the first digit, a ;, then all the pairs of adjacent digits, the digits of each pair separated by , and the pairs separated by ;s, then another ;, then the last digit, then a final ,.



                    (1+),1
                    ,


                    Subtract the pairs of adjacent digits. This leaves ;,; for equal digits and 1s on the greater side for unequal digits. (This could be done as part of the following regex but obviously that wouldn't be so golfy.)



                    ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                    Match the first digit, then any number of pairs of ascending digits, then any number of pairs of equal digits, then any number of pairs of descending digits, then match the first digit again at the very end.






                    share|improve this answer




























                      up vote
                      0
                      down vote














                      Red, 181 bytes



                      func[n][m: last sort copy t: s: form n
                      parse t[opt[copy a to m(a: sort unique a)]copy b thru any m
                      opt[copy c to end(c: sort/reverse unique c)]](s = rejoin[a b c])and(s/1 = last s)]


                      Try it online!



                      More readable:



                      f: func[n][
                      t: s: form n
                      m: last sort copy t
                      parse t [ opt [ copy a to m (a: sort unique a) ]
                      copy b thru any m
                      opt [ copy c to end (c: sort/reverse unique c) ]
                      ]
                      (s = rejoin [ a b c ]) and (s/1 = last s)
                      ]





                      share|improve this answer




























                        up vote
                        0
                        down vote













                        Powershell, 77 bytes





                        ($x=-join("$($args|%{"-$_;$_"})"|iex))-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1]


                        Less golfed test script:



                        $f = {
                        # $args = 1,2,3,3,3,2,1
                        $a=$args|%{"-$_;$_"} # "-1;1","-2;2","-3;3","-3;3","-3;3","-2;2","-1;1"
                        $d="$a" # "-1;1 -2;2 -3;3 -3;3 -3;3 -2;2 -1;1"
                        $x=-join($d|Invoke-Expression) # "-1-1-100111"
                        $x-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1] # $true or $false

                        }

                        @(
                        ,($True , 1,2,3,2,1 )
                        ,($True , 1,2,3,3,3,2,1 )
                        ,($True , 9,9 )
                        ,($True , 3 )
                        ,($True , 2,3,4,5,6,7,9,9,2 )
                        ,($False, 1,2,3,2 )
                        ,($False, 7,7,8,8,9,6 )
                        ,($False, 2,3,2,3,2 )
                        ,($False, 4,5,5,6,6,5,5,4 )
                        ,($False, 5,6,4,5 )
                        ) | % {
                        $expected,$a = $_
                        $result = &$f @a
                        "$($result-eq$expected): $result"
                        }


                        Output:



                        True: True
                        True: True
                        True: True
                        True: True
                        True: True
                        True: False
                        True: False
                        True: False
                        True: False
                        True: False





                        share|improve this answer






























                          up vote
                          0
                          down vote














                          C# (Visual C# Interactive Compiler), 161 bytes





                          s=>{var m=s.OrderBy(c=>c).Last();return s[0]==s.Last()&Enumerable.Range(1,s.Length-1).All(i=>i>s.LastIndexOf(m)?s[i-1]>s[i]:i>s.IndexOf(m)?m==s[i]:s[i-1]<s[i]);}


                          Try it online!



                          Here is an overview of how this works...




                          1. Input is in the form of a string

                          2. Find the largest digit

                          3. Ensure the first and last digits are the same

                          4. Ensure digits after the last occurrence of the largest digit are decreasing

                          5. Ensure digits between the first and last occurrence of the largest digit are equal to the largest digit

                          6. Ensure digits before the first occurrence of the largest digit are increasing






                          share|improve this answer






























                            up vote
                            0
                            down vote














                            Python 3, 114 bytes





                            def f(r):
                            l=[*r]
                            for i in-1,0:
                            while 1<len(l)and l[i]<l[(1,-2)[i]]:l.pop(i)
                            return 2>len({*l})and r[0]==r[-1]


                            Try it online!



                            Way longer than some Python 2 solutions, but this one is def-based and I like it.






                            share|improve this answer




























                              up vote
                              0
                              down vote














                              Ruby, 47 bytes





                              ->n{(r=n.each_cons(2).map{|a,b|a<=>b})==r.sort}


                              Try it online!



                              Input as array of digits, output is boolean.






                              share|improve this answer





















                                Your Answer





                                StackExchange.ifUsing("editor", function () {
                                return StackExchange.using("mathjaxEditing", function () {
                                StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                                StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                                });
                                });
                                }, "mathjax-editing");

                                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',
                                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/3.0/"u003ecc by-sa 3.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%2f176224%2fis-this-number-a-hill-number%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown

























                                19 Answers
                                19






                                active

                                oldest

                                votes








                                19 Answers
                                19






                                active

                                oldest

                                votes









                                active

                                oldest

                                votes






                                active

                                oldest

                                votes








                                up vote
                                9
                                down vote














                                Jelly, 8 bytes



                                _ƝṠÞ+SƊƑ


                                Try it online!



                                How it works



                                _ƝṠÞ+SƊƑ  Main link. Argument: n (integer)

                                _Ɲ Take the differences of neighboring digits.
                                This maps n = abcd to [a-b, b-c, c-d].
                                Ƒ Fixed; apply the link to the left and return 1 if the result is equal to
                                its argument, 0 if not.
                                Ɗ Drei; combine the three links to the left into a monadic chain.
                                ṠÞ Sort the differences by their signs (negative, zero, positive).
                                S Take the sum of the differences, yielding 0 if and only if the
                                first digit is equal to the last.
                                + Add the sum to each difference.





                                share|improve this answer



























                                  up vote
                                  9
                                  down vote














                                  Jelly, 8 bytes



                                  _ƝṠÞ+SƊƑ


                                  Try it online!



                                  How it works



                                  _ƝṠÞ+SƊƑ  Main link. Argument: n (integer)

                                  _Ɲ Take the differences of neighboring digits.
                                  This maps n = abcd to [a-b, b-c, c-d].
                                  Ƒ Fixed; apply the link to the left and return 1 if the result is equal to
                                  its argument, 0 if not.
                                  Ɗ Drei; combine the three links to the left into a monadic chain.
                                  ṠÞ Sort the differences by their signs (negative, zero, positive).
                                  S Take the sum of the differences, yielding 0 if and only if the
                                  first digit is equal to the last.
                                  + Add the sum to each difference.





                                  share|improve this answer

























                                    up vote
                                    9
                                    down vote










                                    up vote
                                    9
                                    down vote










                                    Jelly, 8 bytes



                                    _ƝṠÞ+SƊƑ


                                    Try it online!



                                    How it works



                                    _ƝṠÞ+SƊƑ  Main link. Argument: n (integer)

                                    _Ɲ Take the differences of neighboring digits.
                                    This maps n = abcd to [a-b, b-c, c-d].
                                    Ƒ Fixed; apply the link to the left and return 1 if the result is equal to
                                    its argument, 0 if not.
                                    Ɗ Drei; combine the three links to the left into a monadic chain.
                                    ṠÞ Sort the differences by their signs (negative, zero, positive).
                                    S Take the sum of the differences, yielding 0 if and only if the
                                    first digit is equal to the last.
                                    + Add the sum to each difference.





                                    share|improve this answer















                                    Jelly, 8 bytes



                                    _ƝṠÞ+SƊƑ


                                    Try it online!



                                    How it works



                                    _ƝṠÞ+SƊƑ  Main link. Argument: n (integer)

                                    _Ɲ Take the differences of neighboring digits.
                                    This maps n = abcd to [a-b, b-c, c-d].
                                    Ƒ Fixed; apply the link to the left and return 1 if the result is equal to
                                    its argument, 0 if not.
                                    Ɗ Drei; combine the three links to the left into a monadic chain.
                                    ṠÞ Sort the differences by their signs (negative, zero, positive).
                                    S Take the sum of the differences, yielding 0 if and only if the
                                    first digit is equal to the last.
                                    + Add the sum to each difference.






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Nov 19 at 16:34

























                                    answered Nov 19 at 15:18









                                    Dennis

                                    184k32295731




                                    184k32295731






















                                        up vote
                                        6
                                        down vote













                                        JavaScript (ES6), 62 54 bytes



                                        Takes input as a string. Returns a Boolean value.



                                        s=>s[-[...s].some(p=q=n=>q>(q=Math.sign(p-(p=n))))]==p


                                        Try it online!



                                        Commented



                                        s =>                  // s = input string
                                        s[ // we will eventually access either s[0] or s[-1]
                                        -[...s].some( // depending on the result of this some()
                                        p = q = // initialize p and q to non-numeric values
                                        n => // for each digit n:
                                        q > ( // compare q with
                                        q = // the new value of q,
                                        Math.sign( // defined as the sign of
                                        p - (p = n) // the difference between the current digit and the previous one
                                        )) // yield true if the previous q is greater than the new q
                                        ) // s[-1] being undefined, a truhty some() will force the test to fail
                                        ] == p // otherwise: test if the 1st digit s[0] is equal to the last digit p




                                        JavaScript (ES6), 65 bytes



                                        A solution using a regular expression. Takes input as a string. Returns $0$ or $1$.



                                        s=>/N(,-d+)*(,0)*[^0-]*$/.test([...s].map(p=v=>p-(p=v)))&p==s[0]


                                        Try it online!



                                        How?



                                        We first convert the number to a list of pairwise digit differences in $[-9,9]$:



                                        [...s].map(p = v => p - (p = v))


                                        Example:



                                        "234567992" --> [ NaN, -1, -1, -1, -1, -1, -2, 0, 7 ]


                                        This array is coerced to a string, which gives:



                                        "NaN,-1,-1,-1,-1,-1,-2,0,7"


                                        We apply the following regular expression:



                                         +-----------------------> the second 'N' of 'NaN'
                                        | +------------------> a sequence of negative numbers
                                        | | +------------> a sequence of zeros
                                        | | | +------> a sequence of positive numbers
                                        | | | | +---> end of string
                                        | | | | |
                                        |/¨¨¨¨¨¨/¨¨¨/¨¨¨¨|
                                        /N(,-d+)*(,0)*[^0-]*$/


                                        Finally, we also test if the last digit p is equal to the first digit s[0].






                                        share|improve this answer























                                        • You can save 5 bytes by taking input as an array of digits.
                                          – Shaggy
                                          Nov 19 at 19:11










                                        • @Shaggy I wish I could but this is apparently not allowed .
                                          – Arnauld
                                          Nov 19 at 19:25










                                        • From the spec, with original emphasis: "Input & output can be in any reasonable format" - we usually consider a digit array a reasonable format for an integer.
                                          – Shaggy
                                          Nov 19 at 19:47















                                        up vote
                                        6
                                        down vote













                                        JavaScript (ES6), 62 54 bytes



                                        Takes input as a string. Returns a Boolean value.



                                        s=>s[-[...s].some(p=q=n=>q>(q=Math.sign(p-(p=n))))]==p


                                        Try it online!



                                        Commented



                                        s =>                  // s = input string
                                        s[ // we will eventually access either s[0] or s[-1]
                                        -[...s].some( // depending on the result of this some()
                                        p = q = // initialize p and q to non-numeric values
                                        n => // for each digit n:
                                        q > ( // compare q with
                                        q = // the new value of q,
                                        Math.sign( // defined as the sign of
                                        p - (p = n) // the difference between the current digit and the previous one
                                        )) // yield true if the previous q is greater than the new q
                                        ) // s[-1] being undefined, a truhty some() will force the test to fail
                                        ] == p // otherwise: test if the 1st digit s[0] is equal to the last digit p




                                        JavaScript (ES6), 65 bytes



                                        A solution using a regular expression. Takes input as a string. Returns $0$ or $1$.



                                        s=>/N(,-d+)*(,0)*[^0-]*$/.test([...s].map(p=v=>p-(p=v)))&p==s[0]


                                        Try it online!



                                        How?



                                        We first convert the number to a list of pairwise digit differences in $[-9,9]$:



                                        [...s].map(p = v => p - (p = v))


                                        Example:



                                        "234567992" --> [ NaN, -1, -1, -1, -1, -1, -2, 0, 7 ]


                                        This array is coerced to a string, which gives:



                                        "NaN,-1,-1,-1,-1,-1,-2,0,7"


                                        We apply the following regular expression:



                                         +-----------------------> the second 'N' of 'NaN'
                                        | +------------------> a sequence of negative numbers
                                        | | +------------> a sequence of zeros
                                        | | | +------> a sequence of positive numbers
                                        | | | | +---> end of string
                                        | | | | |
                                        |/¨¨¨¨¨¨/¨¨¨/¨¨¨¨|
                                        /N(,-d+)*(,0)*[^0-]*$/


                                        Finally, we also test if the last digit p is equal to the first digit s[0].






                                        share|improve this answer























                                        • You can save 5 bytes by taking input as an array of digits.
                                          – Shaggy
                                          Nov 19 at 19:11










                                        • @Shaggy I wish I could but this is apparently not allowed .
                                          – Arnauld
                                          Nov 19 at 19:25










                                        • From the spec, with original emphasis: "Input & output can be in any reasonable format" - we usually consider a digit array a reasonable format for an integer.
                                          – Shaggy
                                          Nov 19 at 19:47













                                        up vote
                                        6
                                        down vote










                                        up vote
                                        6
                                        down vote









                                        JavaScript (ES6), 62 54 bytes



                                        Takes input as a string. Returns a Boolean value.



                                        s=>s[-[...s].some(p=q=n=>q>(q=Math.sign(p-(p=n))))]==p


                                        Try it online!



                                        Commented



                                        s =>                  // s = input string
                                        s[ // we will eventually access either s[0] or s[-1]
                                        -[...s].some( // depending on the result of this some()
                                        p = q = // initialize p and q to non-numeric values
                                        n => // for each digit n:
                                        q > ( // compare q with
                                        q = // the new value of q,
                                        Math.sign( // defined as the sign of
                                        p - (p = n) // the difference between the current digit and the previous one
                                        )) // yield true if the previous q is greater than the new q
                                        ) // s[-1] being undefined, a truhty some() will force the test to fail
                                        ] == p // otherwise: test if the 1st digit s[0] is equal to the last digit p




                                        JavaScript (ES6), 65 bytes



                                        A solution using a regular expression. Takes input as a string. Returns $0$ or $1$.



                                        s=>/N(,-d+)*(,0)*[^0-]*$/.test([...s].map(p=v=>p-(p=v)))&p==s[0]


                                        Try it online!



                                        How?



                                        We first convert the number to a list of pairwise digit differences in $[-9,9]$:



                                        [...s].map(p = v => p - (p = v))


                                        Example:



                                        "234567992" --> [ NaN, -1, -1, -1, -1, -1, -2, 0, 7 ]


                                        This array is coerced to a string, which gives:



                                        "NaN,-1,-1,-1,-1,-1,-2,0,7"


                                        We apply the following regular expression:



                                         +-----------------------> the second 'N' of 'NaN'
                                        | +------------------> a sequence of negative numbers
                                        | | +------------> a sequence of zeros
                                        | | | +------> a sequence of positive numbers
                                        | | | | +---> end of string
                                        | | | | |
                                        |/¨¨¨¨¨¨/¨¨¨/¨¨¨¨|
                                        /N(,-d+)*(,0)*[^0-]*$/


                                        Finally, we also test if the last digit p is equal to the first digit s[0].






                                        share|improve this answer














                                        JavaScript (ES6), 62 54 bytes



                                        Takes input as a string. Returns a Boolean value.



                                        s=>s[-[...s].some(p=q=n=>q>(q=Math.sign(p-(p=n))))]==p


                                        Try it online!



                                        Commented



                                        s =>                  // s = input string
                                        s[ // we will eventually access either s[0] or s[-1]
                                        -[...s].some( // depending on the result of this some()
                                        p = q = // initialize p and q to non-numeric values
                                        n => // for each digit n:
                                        q > ( // compare q with
                                        q = // the new value of q,
                                        Math.sign( // defined as the sign of
                                        p - (p = n) // the difference between the current digit and the previous one
                                        )) // yield true if the previous q is greater than the new q
                                        ) // s[-1] being undefined, a truhty some() will force the test to fail
                                        ] == p // otherwise: test if the 1st digit s[0] is equal to the last digit p




                                        JavaScript (ES6), 65 bytes



                                        A solution using a regular expression. Takes input as a string. Returns $0$ or $1$.



                                        s=>/N(,-d+)*(,0)*[^0-]*$/.test([...s].map(p=v=>p-(p=v)))&p==s[0]


                                        Try it online!



                                        How?



                                        We first convert the number to a list of pairwise digit differences in $[-9,9]$:



                                        [...s].map(p = v => p - (p = v))


                                        Example:



                                        "234567992" --> [ NaN, -1, -1, -1, -1, -1, -2, 0, 7 ]


                                        This array is coerced to a string, which gives:



                                        "NaN,-1,-1,-1,-1,-1,-2,0,7"


                                        We apply the following regular expression:



                                         +-----------------------> the second 'N' of 'NaN'
                                        | +------------------> a sequence of negative numbers
                                        | | +------------> a sequence of zeros
                                        | | | +------> a sequence of positive numbers
                                        | | | | +---> end of string
                                        | | | | |
                                        |/¨¨¨¨¨¨/¨¨¨/¨¨¨¨|
                                        /N(,-d+)*(,0)*[^0-]*$/


                                        Finally, we also test if the last digit p is equal to the first digit s[0].







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Nov 19 at 15:34

























                                        answered Nov 19 at 13:14









                                        Arnauld

                                        69.5k586294




                                        69.5k586294












                                        • You can save 5 bytes by taking input as an array of digits.
                                          – Shaggy
                                          Nov 19 at 19:11










                                        • @Shaggy I wish I could but this is apparently not allowed .
                                          – Arnauld
                                          Nov 19 at 19:25










                                        • From the spec, with original emphasis: "Input & output can be in any reasonable format" - we usually consider a digit array a reasonable format for an integer.
                                          – Shaggy
                                          Nov 19 at 19:47


















                                        • You can save 5 bytes by taking input as an array of digits.
                                          – Shaggy
                                          Nov 19 at 19:11










                                        • @Shaggy I wish I could but this is apparently not allowed .
                                          – Arnauld
                                          Nov 19 at 19:25










                                        • From the spec, with original emphasis: "Input & output can be in any reasonable format" - we usually consider a digit array a reasonable format for an integer.
                                          – Shaggy
                                          Nov 19 at 19:47
















                                        You can save 5 bytes by taking input as an array of digits.
                                        – Shaggy
                                        Nov 19 at 19:11




                                        You can save 5 bytes by taking input as an array of digits.
                                        – Shaggy
                                        Nov 19 at 19:11












                                        @Shaggy I wish I could but this is apparently not allowed .
                                        – Arnauld
                                        Nov 19 at 19:25




                                        @Shaggy I wish I could but this is apparently not allowed .
                                        – Arnauld
                                        Nov 19 at 19:25












                                        From the spec, with original emphasis: "Input & output can be in any reasonable format" - we usually consider a digit array a reasonable format for an integer.
                                        – Shaggy
                                        Nov 19 at 19:47




                                        From the spec, with original emphasis: "Input & output can be in any reasonable format" - we usually consider a digit array a reasonable format for an integer.
                                        – Shaggy
                                        Nov 19 at 19:47










                                        up vote
                                        4
                                        down vote













                                        Pyth, 16 bytes



                                        &SI_._MJ.+jQT!sJ


                                        Try the test suite.



                                                  jQT          input in base 10
                                        J.+ J = differences: [3,1,4,1] -> [-2,3,-3]
                                        ._M Signs of each element of J
                                        _ Reverse the list
                                        SI and check if it is Invariant under Sorting.
                                        If this is true, J consists of some positive numbers,
                                        followed by some 0s, followed by some negative numbers,
                                        which is what we want.
                                        !sJ Now we check the other hill condition by ensuring
                                        sum(differences) = 0; i.e. the first and last digit are equal.
                                        & We take the logical AND of both conditions.





                                        share|improve this answer

























                                          up vote
                                          4
                                          down vote













                                          Pyth, 16 bytes



                                          &SI_._MJ.+jQT!sJ


                                          Try the test suite.



                                                    jQT          input in base 10
                                          J.+ J = differences: [3,1,4,1] -> [-2,3,-3]
                                          ._M Signs of each element of J
                                          _ Reverse the list
                                          SI and check if it is Invariant under Sorting.
                                          If this is true, J consists of some positive numbers,
                                          followed by some 0s, followed by some negative numbers,
                                          which is what we want.
                                          !sJ Now we check the other hill condition by ensuring
                                          sum(differences) = 0; i.e. the first and last digit are equal.
                                          & We take the logical AND of both conditions.





                                          share|improve this answer























                                            up vote
                                            4
                                            down vote










                                            up vote
                                            4
                                            down vote









                                            Pyth, 16 bytes



                                            &SI_._MJ.+jQT!sJ


                                            Try the test suite.



                                                      jQT          input in base 10
                                            J.+ J = differences: [3,1,4,1] -> [-2,3,-3]
                                            ._M Signs of each element of J
                                            _ Reverse the list
                                            SI and check if it is Invariant under Sorting.
                                            If this is true, J consists of some positive numbers,
                                            followed by some 0s, followed by some negative numbers,
                                            which is what we want.
                                            !sJ Now we check the other hill condition by ensuring
                                            sum(differences) = 0; i.e. the first and last digit are equal.
                                            & We take the logical AND of both conditions.





                                            share|improve this answer












                                            Pyth, 16 bytes



                                            &SI_._MJ.+jQT!sJ


                                            Try the test suite.



                                                      jQT          input in base 10
                                            J.+ J = differences: [3,1,4,1] -> [-2,3,-3]
                                            ._M Signs of each element of J
                                            _ Reverse the list
                                            SI and check if it is Invariant under Sorting.
                                            If this is true, J consists of some positive numbers,
                                            followed by some 0s, followed by some negative numbers,
                                            which is what we want.
                                            !sJ Now we check the other hill condition by ensuring
                                            sum(differences) = 0; i.e. the first and last digit are equal.
                                            & We take the logical AND of both conditions.






                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Nov 19 at 11:28









                                            lirtosiast

                                            15.6k436105




                                            15.6k436105






















                                                up vote
                                                4
                                                down vote














                                                Jelly, 11 bytes



                                                DIµṠNṢƑaS¬$


                                                Explanation:



                                                D               Convert to a list of Digits.
                                                I Increments; compute differences between successive elements.
                                                µ Start new µonadic link.
                                                Ṡ Find Ṡign of each increment
                                                N then negate;
                                                ṢƑ is the result invariant under Ṣorting?
                                                If so, the increments consist of some positive numbers,
                                                followed by some 0s, followed by some negative numbers,
                                                which is what we want.
                                                a Logical AND this result with
                                                S¬$ logical NOT of the Sum of the increments.
                                                If the sum of the increments is zero, first and last digits are equal.


                                                Try it online!






                                                share|improve this answer



























                                                  up vote
                                                  4
                                                  down vote














                                                  Jelly, 11 bytes



                                                  DIµṠNṢƑaS¬$


                                                  Explanation:



                                                  D               Convert to a list of Digits.
                                                  I Increments; compute differences between successive elements.
                                                  µ Start new µonadic link.
                                                  Ṡ Find Ṡign of each increment
                                                  N then negate;
                                                  ṢƑ is the result invariant under Ṣorting?
                                                  If so, the increments consist of some positive numbers,
                                                  followed by some 0s, followed by some negative numbers,
                                                  which is what we want.
                                                  a Logical AND this result with
                                                  S¬$ logical NOT of the Sum of the increments.
                                                  If the sum of the increments is zero, first and last digits are equal.


                                                  Try it online!






                                                  share|improve this answer

























                                                    up vote
                                                    4
                                                    down vote










                                                    up vote
                                                    4
                                                    down vote










                                                    Jelly, 11 bytes



                                                    DIµṠNṢƑaS¬$


                                                    Explanation:



                                                    D               Convert to a list of Digits.
                                                    I Increments; compute differences between successive elements.
                                                    µ Start new µonadic link.
                                                    Ṡ Find Ṡign of each increment
                                                    N then negate;
                                                    ṢƑ is the result invariant under Ṣorting?
                                                    If so, the increments consist of some positive numbers,
                                                    followed by some 0s, followed by some negative numbers,
                                                    which is what we want.
                                                    a Logical AND this result with
                                                    S¬$ logical NOT of the Sum of the increments.
                                                    If the sum of the increments is zero, first and last digits are equal.


                                                    Try it online!






                                                    share|improve this answer















                                                    Jelly, 11 bytes



                                                    DIµṠNṢƑaS¬$


                                                    Explanation:



                                                    D               Convert to a list of Digits.
                                                    I Increments; compute differences between successive elements.
                                                    µ Start new µonadic link.
                                                    Ṡ Find Ṡign of each increment
                                                    N then negate;
                                                    ṢƑ is the result invariant under Ṣorting?
                                                    If so, the increments consist of some positive numbers,
                                                    followed by some 0s, followed by some negative numbers,
                                                    which is what we want.
                                                    a Logical AND this result with
                                                    S¬$ logical NOT of the Sum of the increments.
                                                    If the sum of the increments is zero, first and last digits are equal.


                                                    Try it online!







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Nov 19 at 11:46

























                                                    answered Nov 19 at 11:04









                                                    lirtosiast

                                                    15.6k436105




                                                    15.6k436105






















                                                        up vote
                                                        4
                                                        down vote














                                                        Perl 6, 39 bytes





                                                        {.[0]==.tail&&[<=] $_ Z<=>.skip}o*.comb


                                                        Try it online!



                                                        Explanation



                                                        { ... }o.comb  # Split into digits and feed into block
                                                        .[0]==.tail # First element equals last
                                                        && # and
                                                        $_ Z<=>.skip # Pairwise application of three-way comparator
                                                        [<=] # Results never decrease





                                                        share|improve this answer





















                                                        • I was literally seconds away from posting this lol.
                                                          – Jo King
                                                          Nov 19 at 12:41















                                                        up vote
                                                        4
                                                        down vote














                                                        Perl 6, 39 bytes





                                                        {.[0]==.tail&&[<=] $_ Z<=>.skip}o*.comb


                                                        Try it online!



                                                        Explanation



                                                        { ... }o.comb  # Split into digits and feed into block
                                                        .[0]==.tail # First element equals last
                                                        && # and
                                                        $_ Z<=>.skip # Pairwise application of three-way comparator
                                                        [<=] # Results never decrease





                                                        share|improve this answer





















                                                        • I was literally seconds away from posting this lol.
                                                          – Jo King
                                                          Nov 19 at 12:41













                                                        up vote
                                                        4
                                                        down vote










                                                        up vote
                                                        4
                                                        down vote










                                                        Perl 6, 39 bytes





                                                        {.[0]==.tail&&[<=] $_ Z<=>.skip}o*.comb


                                                        Try it online!



                                                        Explanation



                                                        { ... }o.comb  # Split into digits and feed into block
                                                        .[0]==.tail # First element equals last
                                                        && # and
                                                        $_ Z<=>.skip # Pairwise application of three-way comparator
                                                        [<=] # Results never decrease





                                                        share|improve this answer













                                                        Perl 6, 39 bytes





                                                        {.[0]==.tail&&[<=] $_ Z<=>.skip}o*.comb


                                                        Try it online!



                                                        Explanation



                                                        { ... }o.comb  # Split into digits and feed into block
                                                        .[0]==.tail # First element equals last
                                                        && # and
                                                        $_ Z<=>.skip # Pairwise application of three-way comparator
                                                        [<=] # Results never decrease






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Nov 19 at 12:31









                                                        nwellnhof

                                                        6,1981125




                                                        6,1981125












                                                        • I was literally seconds away from posting this lol.
                                                          – Jo King
                                                          Nov 19 at 12:41


















                                                        • I was literally seconds away from posting this lol.
                                                          – Jo King
                                                          Nov 19 at 12:41
















                                                        I was literally seconds away from posting this lol.
                                                        – Jo King
                                                        Nov 19 at 12:41




                                                        I was literally seconds away from posting this lol.
                                                        – Jo King
                                                        Nov 19 at 12:41










                                                        up vote
                                                        3
                                                        down vote














                                                        Python 2, 114 112 bytes





                                                        lambda n:all((n[0]==n[-1])*sorted(set(x))==list(x)[::d]for x,d in zip(n.split(max(n)*n.count(max(n)),1),[1,-1]))


                                                        Try it online!






                                                        share|improve this answer

























                                                          up vote
                                                          3
                                                          down vote














                                                          Python 2, 114 112 bytes





                                                          lambda n:all((n[0]==n[-1])*sorted(set(x))==list(x)[::d]for x,d in zip(n.split(max(n)*n.count(max(n)),1),[1,-1]))


                                                          Try it online!






                                                          share|improve this answer























                                                            up vote
                                                            3
                                                            down vote










                                                            up vote
                                                            3
                                                            down vote










                                                            Python 2, 114 112 bytes





                                                            lambda n:all((n[0]==n[-1])*sorted(set(x))==list(x)[::d]for x,d in zip(n.split(max(n)*n.count(max(n)),1),[1,-1]))


                                                            Try it online!






                                                            share|improve this answer













                                                            Python 2, 114 112 bytes





                                                            lambda n:all((n[0]==n[-1])*sorted(set(x))==list(x)[::d]for x,d in zip(n.split(max(n)*n.count(max(n)),1),[1,-1]))


                                                            Try it online!







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Nov 19 at 11:12









                                                            TFeld

                                                            13.7k21139




                                                            13.7k21139






















                                                                up vote
                                                                3
                                                                down vote














                                                                R, 65 bytes



                                                                Takes strings. Took the idea for checking sort invariance from the Pyth answer.





                                                                function(a)!sum(d<-diff(utf8ToInt(a)))&all(sort(k<-sign(d),T)==k)


                                                                Try it online!






                                                                share|improve this answer



























                                                                  up vote
                                                                  3
                                                                  down vote














                                                                  R, 65 bytes



                                                                  Takes strings. Took the idea for checking sort invariance from the Pyth answer.





                                                                  function(a)!sum(d<-diff(utf8ToInt(a)))&all(sort(k<-sign(d),T)==k)


                                                                  Try it online!






                                                                  share|improve this answer

























                                                                    up vote
                                                                    3
                                                                    down vote










                                                                    up vote
                                                                    3
                                                                    down vote










                                                                    R, 65 bytes



                                                                    Takes strings. Took the idea for checking sort invariance from the Pyth answer.





                                                                    function(a)!sum(d<-diff(utf8ToInt(a)))&all(sort(k<-sign(d),T)==k)


                                                                    Try it online!






                                                                    share|improve this answer















                                                                    R, 65 bytes



                                                                    Takes strings. Took the idea for checking sort invariance from the Pyth answer.





                                                                    function(a)!sum(d<-diff(utf8ToInt(a)))&all(sort(k<-sign(d),T)==k)


                                                                    Try it online!







                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Nov 20 at 7:17

























                                                                    answered Nov 20 at 0:44









                                                                    J.Doe

                                                                    2,031112




                                                                    2,031112






















                                                                        up vote
                                                                        2
                                                                        down vote














                                                                        05AB1E, 19 17 13 12 bytes



                                                                        ¥D.±Â{RQsO_*


                                                                        -5 bytes by creating a port of @lirtosiast's Pyth answer.



                                                                        Try it online or verify all test cases.



                                                                        Explanation:





                                                                        ¥           # Push the deltas of the digits of the (implicit) input
                                                                        # i.e. 4588774 → [1,3,0,-1,0,-3]
                                                                        D # Duplicate this list
                                                                        .± # Get the sign of each
                                                                        # [1,3,0,-1,0,-3] → [1,1,0,-1,0,-1]
                                                                        Â # Bifurcate (short for DR: Duplicate and Reverse copy)
                                                                        # i.e. [1,1,0,-1,0,-1] → [-1,0,-1,0,1,1]
                                                                        { # Sort the copy
                                                                        # i.e. [-1,0,-1,0,1,1] → [-1,-1,0,0,1,1]
                                                                        R # Reverse it
                                                                        # i.e. [1,1,0,0,-1,-1]
                                                                        Q # And check if they are equal
                                                                        # i.e. [1,1,0,-1,0,-1] and [1,1,0,0,-1,-1] → 0 (falsey)
                                                                        s # Swap to get the list of deltas again
                                                                        O # Take the sum
                                                                        # i.e. [1,3,0,-1,0,-3] → 0
                                                                        _ # And check if it's exactly 0
                                                                        # 0 → 1 (truthy)
                                                                        * # Check if both are truthy (and output implicitly)
                                                                        # i.e. 0 and 1 → 0 (falsey)


                                                                        Â{RQ can alternatively be (Â{Q for the same byte-count, where ( negates each sign: Try it online.






                                                                        share|improve this answer



























                                                                          up vote
                                                                          2
                                                                          down vote














                                                                          05AB1E, 19 17 13 12 bytes



                                                                          ¥D.±Â{RQsO_*


                                                                          -5 bytes by creating a port of @lirtosiast's Pyth answer.



                                                                          Try it online or verify all test cases.



                                                                          Explanation:





                                                                          ¥           # Push the deltas of the digits of the (implicit) input
                                                                          # i.e. 4588774 → [1,3,0,-1,0,-3]
                                                                          D # Duplicate this list
                                                                          .± # Get the sign of each
                                                                          # [1,3,0,-1,0,-3] → [1,1,0,-1,0,-1]
                                                                          Â # Bifurcate (short for DR: Duplicate and Reverse copy)
                                                                          # i.e. [1,1,0,-1,0,-1] → [-1,0,-1,0,1,1]
                                                                          { # Sort the copy
                                                                          # i.e. [-1,0,-1,0,1,1] → [-1,-1,0,0,1,1]
                                                                          R # Reverse it
                                                                          # i.e. [1,1,0,0,-1,-1]
                                                                          Q # And check if they are equal
                                                                          # i.e. [1,1,0,-1,0,-1] and [1,1,0,0,-1,-1] → 0 (falsey)
                                                                          s # Swap to get the list of deltas again
                                                                          O # Take the sum
                                                                          # i.e. [1,3,0,-1,0,-3] → 0
                                                                          _ # And check if it's exactly 0
                                                                          # 0 → 1 (truthy)
                                                                          * # Check if both are truthy (and output implicitly)
                                                                          # i.e. 0 and 1 → 0 (falsey)


                                                                          Â{RQ can alternatively be (Â{Q for the same byte-count, where ( negates each sign: Try it online.






                                                                          share|improve this answer

























                                                                            up vote
                                                                            2
                                                                            down vote










                                                                            up vote
                                                                            2
                                                                            down vote










                                                                            05AB1E, 19 17 13 12 bytes



                                                                            ¥D.±Â{RQsO_*


                                                                            -5 bytes by creating a port of @lirtosiast's Pyth answer.



                                                                            Try it online or verify all test cases.



                                                                            Explanation:





                                                                            ¥           # Push the deltas of the digits of the (implicit) input
                                                                            # i.e. 4588774 → [1,3,0,-1,0,-3]
                                                                            D # Duplicate this list
                                                                            .± # Get the sign of each
                                                                            # [1,3,0,-1,0,-3] → [1,1,0,-1,0,-1]
                                                                            Â # Bifurcate (short for DR: Duplicate and Reverse copy)
                                                                            # i.e. [1,1,0,-1,0,-1] → [-1,0,-1,0,1,1]
                                                                            { # Sort the copy
                                                                            # i.e. [-1,0,-1,0,1,1] → [-1,-1,0,0,1,1]
                                                                            R # Reverse it
                                                                            # i.e. [1,1,0,0,-1,-1]
                                                                            Q # And check if they are equal
                                                                            # i.e. [1,1,0,-1,0,-1] and [1,1,0,0,-1,-1] → 0 (falsey)
                                                                            s # Swap to get the list of deltas again
                                                                            O # Take the sum
                                                                            # i.e. [1,3,0,-1,0,-3] → 0
                                                                            _ # And check if it's exactly 0
                                                                            # 0 → 1 (truthy)
                                                                            * # Check if both are truthy (and output implicitly)
                                                                            # i.e. 0 and 1 → 0 (falsey)


                                                                            Â{RQ can alternatively be (Â{Q for the same byte-count, where ( negates each sign: Try it online.






                                                                            share|improve this answer















                                                                            05AB1E, 19 17 13 12 bytes



                                                                            ¥D.±Â{RQsO_*


                                                                            -5 bytes by creating a port of @lirtosiast's Pyth answer.



                                                                            Try it online or verify all test cases.



                                                                            Explanation:





                                                                            ¥           # Push the deltas of the digits of the (implicit) input
                                                                            # i.e. 4588774 → [1,3,0,-1,0,-3]
                                                                            D # Duplicate this list
                                                                            .± # Get the sign of each
                                                                            # [1,3,0,-1,0,-3] → [1,1,0,-1,0,-1]
                                                                            Â # Bifurcate (short for DR: Duplicate and Reverse copy)
                                                                            # i.e. [1,1,0,-1,0,-1] → [-1,0,-1,0,1,1]
                                                                            { # Sort the copy
                                                                            # i.e. [-1,0,-1,0,1,1] → [-1,-1,0,0,1,1]
                                                                            R # Reverse it
                                                                            # i.e. [1,1,0,0,-1,-1]
                                                                            Q # And check if they are equal
                                                                            # i.e. [1,1,0,-1,0,-1] and [1,1,0,0,-1,-1] → 0 (falsey)
                                                                            s # Swap to get the list of deltas again
                                                                            O # Take the sum
                                                                            # i.e. [1,3,0,-1,0,-3] → 0
                                                                            _ # And check if it's exactly 0
                                                                            # 0 → 1 (truthy)
                                                                            * # Check if both are truthy (and output implicitly)
                                                                            # i.e. 0 and 1 → 0 (falsey)


                                                                            Â{RQ can alternatively be (Â{Q for the same byte-count, where ( negates each sign: Try it online.







                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Nov 19 at 12:49

























                                                                            answered Nov 19 at 11:25









                                                                            Kevin Cruijssen

                                                                            34.4k554182




                                                                            34.4k554182






















                                                                                up vote
                                                                                2
                                                                                down vote













                                                                                J, 23 bytes



                                                                                [:((0=+/)**-:*/:*)2-/]


                                                                                Idea stolen from the Jelly answers. Just wanted to see how short I could make it in J.



                                                                                Try it online!






                                                                                share|improve this answer



























                                                                                  up vote
                                                                                  2
                                                                                  down vote













                                                                                  J, 23 bytes



                                                                                  [:((0=+/)**-:*/:*)2-/]


                                                                                  Idea stolen from the Jelly answers. Just wanted to see how short I could make it in J.



                                                                                  Try it online!






                                                                                  share|improve this answer

























                                                                                    up vote
                                                                                    2
                                                                                    down vote










                                                                                    up vote
                                                                                    2
                                                                                    down vote









                                                                                    J, 23 bytes



                                                                                    [:((0=+/)**-:*/:*)2-/]


                                                                                    Idea stolen from the Jelly answers. Just wanted to see how short I could make it in J.



                                                                                    Try it online!






                                                                                    share|improve this answer














                                                                                    J, 23 bytes



                                                                                    [:((0=+/)**-:*/:*)2-/]


                                                                                    Idea stolen from the Jelly answers. Just wanted to see how short I could make it in J.



                                                                                    Try it online!







                                                                                    share|improve this answer














                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited Nov 19 at 21:15

























                                                                                    answered Nov 19 at 21:05









                                                                                    Jonah

                                                                                    1,981816




                                                                                    1,981816






















                                                                                        up vote
                                                                                        2
                                                                                        down vote














                                                                                        MATL, 12 bytes



                                                                                        dZSd1<AGds~*


                                                                                        Try it online!



                                                                                        Explanation



                                                                                        Input is a string of digits. Output is a 1 or 0. The number 222222 is a hill number according to this program. Saved 2 bytes by copying Dennis' method for checking equality of the first and last digits.



                                                                                        d               % Takes the difference between digits
                                                                                        ZS % Calculate the sign.
                                                                                        d % Take the difference again.
                                                                                        1< % A number is a hill number if these differences are < 1.
                                                                                        A % Truthy iff above is all true OR if array is empty (necessary for short inputs)
                                                                                        Gds % Push the input, and sum all the differences.
                                                                                        ~ % Negate
                                                                                        * % Multiply the two tests (=logical AND).





                                                                                        share|improve this answer



























                                                                                          up vote
                                                                                          2
                                                                                          down vote














                                                                                          MATL, 12 bytes



                                                                                          dZSd1<AGds~*


                                                                                          Try it online!



                                                                                          Explanation



                                                                                          Input is a string of digits. Output is a 1 or 0. The number 222222 is a hill number according to this program. Saved 2 bytes by copying Dennis' method for checking equality of the first and last digits.



                                                                                          d               % Takes the difference between digits
                                                                                          ZS % Calculate the sign.
                                                                                          d % Take the difference again.
                                                                                          1< % A number is a hill number if these differences are < 1.
                                                                                          A % Truthy iff above is all true OR if array is empty (necessary for short inputs)
                                                                                          Gds % Push the input, and sum all the differences.
                                                                                          ~ % Negate
                                                                                          * % Multiply the two tests (=logical AND).





                                                                                          share|improve this answer

























                                                                                            up vote
                                                                                            2
                                                                                            down vote










                                                                                            up vote
                                                                                            2
                                                                                            down vote










                                                                                            MATL, 12 bytes



                                                                                            dZSd1<AGds~*


                                                                                            Try it online!



                                                                                            Explanation



                                                                                            Input is a string of digits. Output is a 1 or 0. The number 222222 is a hill number according to this program. Saved 2 bytes by copying Dennis' method for checking equality of the first and last digits.



                                                                                            d               % Takes the difference between digits
                                                                                            ZS % Calculate the sign.
                                                                                            d % Take the difference again.
                                                                                            1< % A number is a hill number if these differences are < 1.
                                                                                            A % Truthy iff above is all true OR if array is empty (necessary for short inputs)
                                                                                            Gds % Push the input, and sum all the differences.
                                                                                            ~ % Negate
                                                                                            * % Multiply the two tests (=logical AND).





                                                                                            share|improve this answer















                                                                                            MATL, 12 bytes



                                                                                            dZSd1<AGds~*


                                                                                            Try it online!



                                                                                            Explanation



                                                                                            Input is a string of digits. Output is a 1 or 0. The number 222222 is a hill number according to this program. Saved 2 bytes by copying Dennis' method for checking equality of the first and last digits.



                                                                                            d               % Takes the difference between digits
                                                                                            ZS % Calculate the sign.
                                                                                            d % Take the difference again.
                                                                                            1< % A number is a hill number if these differences are < 1.
                                                                                            A % Truthy iff above is all true OR if array is empty (necessary for short inputs)
                                                                                            Gds % Push the input, and sum all the differences.
                                                                                            ~ % Negate
                                                                                            * % Multiply the two tests (=logical AND).






                                                                                            share|improve this answer














                                                                                            share|improve this answer



                                                                                            share|improve this answer








                                                                                            edited 2 days ago

























                                                                                            answered Nov 20 at 11:13









                                                                                            Sanchises

                                                                                            5,73212351




                                                                                            5,73212351






















                                                                                                up vote
                                                                                                1
                                                                                                down vote













                                                                                                Japt, 11 bytes



                                                                                                Takes input as a digit array.



                                                                                                ä-
                                                                                                eUñg)«Ux


                                                                                                Try it or run all test cases






                                                                                                share|improve this answer

























                                                                                                  up vote
                                                                                                  1
                                                                                                  down vote













                                                                                                  Japt, 11 bytes



                                                                                                  Takes input as a digit array.



                                                                                                  ä-
                                                                                                  eUñg)«Ux


                                                                                                  Try it or run all test cases






                                                                                                  share|improve this answer























                                                                                                    up vote
                                                                                                    1
                                                                                                    down vote










                                                                                                    up vote
                                                                                                    1
                                                                                                    down vote









                                                                                                    Japt, 11 bytes



                                                                                                    Takes input as a digit array.



                                                                                                    ä-
                                                                                                    eUñg)«Ux


                                                                                                    Try it or run all test cases






                                                                                                    share|improve this answer












                                                                                                    Japt, 11 bytes



                                                                                                    Takes input as a digit array.



                                                                                                    ä-
                                                                                                    eUñg)«Ux


                                                                                                    Try it or run all test cases







                                                                                                    share|improve this answer












                                                                                                    share|improve this answer



                                                                                                    share|improve this answer










                                                                                                    answered Nov 19 at 18:15









                                                                                                    Shaggy

                                                                                                    18.2k21663




                                                                                                    18.2k21663






















                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote














                                                                                                        Python 2, 53 bytes





                                                                                                        def f(s):x=map(cmp,s,s[1:]);s[:sorted(x)==x]!=s[-1]>_


                                                                                                        Takes input as a string. Output is via presence or absence of an exception.



                                                                                                        Try it online!






                                                                                                        Python 2, 62 bytes





                                                                                                        lambda s:s[:eval('<='.join(map(str,map(cmp,s,s[1:]))))]==s[-1]


                                                                                                        Takes input as a string and returns a Boolean.



                                                                                                        Try it online!






                                                                                                        share|improve this answer























                                                                                                        • Whoa, I've been hurting my head for hours and I couldn't even come up with something shorter than the combined byte count of your 2 solutions ! Cheers.
                                                                                                          – etene
                                                                                                          Nov 20 at 17:01















                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote














                                                                                                        Python 2, 53 bytes





                                                                                                        def f(s):x=map(cmp,s,s[1:]);s[:sorted(x)==x]!=s[-1]>_


                                                                                                        Takes input as a string. Output is via presence or absence of an exception.



                                                                                                        Try it online!






                                                                                                        Python 2, 62 bytes





                                                                                                        lambda s:s[:eval('<='.join(map(str,map(cmp,s,s[1:]))))]==s[-1]


                                                                                                        Takes input as a string and returns a Boolean.



                                                                                                        Try it online!






                                                                                                        share|improve this answer























                                                                                                        • Whoa, I've been hurting my head for hours and I couldn't even come up with something shorter than the combined byte count of your 2 solutions ! Cheers.
                                                                                                          – etene
                                                                                                          Nov 20 at 17:01













                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote










                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote










                                                                                                        Python 2, 53 bytes





                                                                                                        def f(s):x=map(cmp,s,s[1:]);s[:sorted(x)==x]!=s[-1]>_


                                                                                                        Takes input as a string. Output is via presence or absence of an exception.



                                                                                                        Try it online!






                                                                                                        Python 2, 62 bytes





                                                                                                        lambda s:s[:eval('<='.join(map(str,map(cmp,s,s[1:]))))]==s[-1]


                                                                                                        Takes input as a string and returns a Boolean.



                                                                                                        Try it online!






                                                                                                        share|improve this answer















                                                                                                        Python 2, 53 bytes





                                                                                                        def f(s):x=map(cmp,s,s[1:]);s[:sorted(x)==x]!=s[-1]>_


                                                                                                        Takes input as a string. Output is via presence or absence of an exception.



                                                                                                        Try it online!






                                                                                                        Python 2, 62 bytes





                                                                                                        lambda s:s[:eval('<='.join(map(str,map(cmp,s,s[1:]))))]==s[-1]


                                                                                                        Takes input as a string and returns a Boolean.



                                                                                                        Try it online!







                                                                                                        share|improve this answer














                                                                                                        share|improve this answer



                                                                                                        share|improve this answer








                                                                                                        edited Nov 20 at 15:06

























                                                                                                        answered Nov 20 at 14:35









                                                                                                        Dennis

                                                                                                        184k32295731




                                                                                                        184k32295731












                                                                                                        • Whoa, I've been hurting my head for hours and I couldn't even come up with something shorter than the combined byte count of your 2 solutions ! Cheers.
                                                                                                          – etene
                                                                                                          Nov 20 at 17:01


















                                                                                                        • Whoa, I've been hurting my head for hours and I couldn't even come up with something shorter than the combined byte count of your 2 solutions ! Cheers.
                                                                                                          – etene
                                                                                                          Nov 20 at 17:01
















                                                                                                        Whoa, I've been hurting my head for hours and I couldn't even come up with something shorter than the combined byte count of your 2 solutions ! Cheers.
                                                                                                        – etene
                                                                                                        Nov 20 at 17:01




                                                                                                        Whoa, I've been hurting my head for hours and I couldn't even come up with something shorter than the combined byte count of your 2 solutions ! Cheers.
                                                                                                        – etene
                                                                                                        Nov 20 at 17:01










                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote













                                                                                                        Mathematica/Wolfram Language, 69 64 bytes



                                                                                                        Pure function. Takes input as an integer, returns True or False.



                                                                                                        Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&


                                                                                                        Explanation:



                                                                                                        The first clause checks the "hilliness":





                                                                                                        • IntegerDigits: Get digits from integer. Store in y.


                                                                                                        • -Differences: Take successive differences and flip signs.


                                                                                                        • Sign: Replace each entry with +1 if positive, 0 if zero, and -1 if negative. Store in x.


                                                                                                        • Sort: Sort list of +1, 0, -1 from smallest to largest. Compare to original list in x.


                                                                                                        The second clause checks whether the first and last digits are equal.



                                                                                                        A tip of the hat to @IanMiller for tips on refining this code.






                                                                                                        share|improve this answer























                                                                                                        • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                          – Michael Seifert
                                                                                                          Nov 19 at 18:58












                                                                                                        • Can save 5 bytes with the following changes: Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&
                                                                                                          – Ian Miller
                                                                                                          16 hours ago

















                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote













                                                                                                        Mathematica/Wolfram Language, 69 64 bytes



                                                                                                        Pure function. Takes input as an integer, returns True or False.



                                                                                                        Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&


                                                                                                        Explanation:



                                                                                                        The first clause checks the "hilliness":





                                                                                                        • IntegerDigits: Get digits from integer. Store in y.


                                                                                                        • -Differences: Take successive differences and flip signs.


                                                                                                        • Sign: Replace each entry with +1 if positive, 0 if zero, and -1 if negative. Store in x.


                                                                                                        • Sort: Sort list of +1, 0, -1 from smallest to largest. Compare to original list in x.


                                                                                                        The second clause checks whether the first and last digits are equal.



                                                                                                        A tip of the hat to @IanMiller for tips on refining this code.






                                                                                                        share|improve this answer























                                                                                                        • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                          – Michael Seifert
                                                                                                          Nov 19 at 18:58












                                                                                                        • Can save 5 bytes with the following changes: Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&
                                                                                                          – Ian Miller
                                                                                                          16 hours ago















                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote










                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote









                                                                                                        Mathematica/Wolfram Language, 69 64 bytes



                                                                                                        Pure function. Takes input as an integer, returns True or False.



                                                                                                        Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&


                                                                                                        Explanation:



                                                                                                        The first clause checks the "hilliness":





                                                                                                        • IntegerDigits: Get digits from integer. Store in y.


                                                                                                        • -Differences: Take successive differences and flip signs.


                                                                                                        • Sign: Replace each entry with +1 if positive, 0 if zero, and -1 if negative. Store in x.


                                                                                                        • Sort: Sort list of +1, 0, -1 from smallest to largest. Compare to original list in x.


                                                                                                        The second clause checks whether the first and last digits are equal.



                                                                                                        A tip of the hat to @IanMiller for tips on refining this code.






                                                                                                        share|improve this answer














                                                                                                        Mathematica/Wolfram Language, 69 64 bytes



                                                                                                        Pure function. Takes input as an integer, returns True or False.



                                                                                                        Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&


                                                                                                        Explanation:



                                                                                                        The first clause checks the "hilliness":





                                                                                                        • IntegerDigits: Get digits from integer. Store in y.


                                                                                                        • -Differences: Take successive differences and flip signs.


                                                                                                        • Sign: Replace each entry with +1 if positive, 0 if zero, and -1 if negative. Store in x.


                                                                                                        • Sort: Sort list of +1, 0, -1 from smallest to largest. Compare to original list in x.


                                                                                                        The second clause checks whether the first and last digits are equal.



                                                                                                        A tip of the hat to @IanMiller for tips on refining this code.







                                                                                                        share|improve this answer














                                                                                                        share|improve this answer



                                                                                                        share|improve this answer








                                                                                                        edited 14 hours ago

























                                                                                                        answered Nov 19 at 18:57









                                                                                                        Michael Seifert

                                                                                                        1614




                                                                                                        1614












                                                                                                        • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                          – Michael Seifert
                                                                                                          Nov 19 at 18:58












                                                                                                        • Can save 5 bytes with the following changes: Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&
                                                                                                          – Ian Miller
                                                                                                          16 hours ago




















                                                                                                        • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                          – Michael Seifert
                                                                                                          Nov 19 at 18:58












                                                                                                        • Can save 5 bytes with the following changes: Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&
                                                                                                          – Ian Miller
                                                                                                          16 hours ago


















                                                                                                        The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                        – Michael Seifert
                                                                                                        Nov 19 at 18:58






                                                                                                        The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                        – Michael Seifert
                                                                                                        Nov 19 at 18:58














                                                                                                        Can save 5 bytes with the following changes: Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&
                                                                                                        – Ian Miller
                                                                                                        16 hours ago






                                                                                                        Can save 5 bytes with the following changes: Sort[x=Sign@-Differences[y=IntegerDigits@#]]==x&&y[[1]]==Last@y&
                                                                                                        – Ian Miller
                                                                                                        16 hours ago












                                                                                                        up vote
                                                                                                        0
                                                                                                        down vote














                                                                                                        Retina 0.8.2, 52 bytes



                                                                                                        .
                                                                                                        $*1;$&$*1,
                                                                                                        (1+),1
                                                                                                        ,
                                                                                                        ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                                                                                                        Try it online! Link includes test cases. Explanation:



                                                                                                        .
                                                                                                        $*1;$&$*1,


                                                                                                        Convert each digit to unary twice, separated by ;s and terminated by ,s. However, you can then think of the result as the first digit, a ;, then all the pairs of adjacent digits, the digits of each pair separated by , and the pairs separated by ;s, then another ;, then the last digit, then a final ,.



                                                                                                        (1+),1
                                                                                                        ,


                                                                                                        Subtract the pairs of adjacent digits. This leaves ;,; for equal digits and 1s on the greater side for unequal digits. (This could be done as part of the following regex but obviously that wouldn't be so golfy.)



                                                                                                        ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                                                                                                        Match the first digit, then any number of pairs of ascending digits, then any number of pairs of equal digits, then any number of pairs of descending digits, then match the first digit again at the very end.






                                                                                                        share|improve this answer

























                                                                                                          up vote
                                                                                                          0
                                                                                                          down vote














                                                                                                          Retina 0.8.2, 52 bytes



                                                                                                          .
                                                                                                          $*1;$&$*1,
                                                                                                          (1+),1
                                                                                                          ,
                                                                                                          ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                                                                                                          Try it online! Link includes test cases. Explanation:



                                                                                                          .
                                                                                                          $*1;$&$*1,


                                                                                                          Convert each digit to unary twice, separated by ;s and terminated by ,s. However, you can then think of the result as the first digit, a ;, then all the pairs of adjacent digits, the digits of each pair separated by , and the pairs separated by ;s, then another ;, then the last digit, then a final ,.



                                                                                                          (1+),1
                                                                                                          ,


                                                                                                          Subtract the pairs of adjacent digits. This leaves ;,; for equal digits and 1s on the greater side for unequal digits. (This could be done as part of the following regex but obviously that wouldn't be so golfy.)



                                                                                                          ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                                                                                                          Match the first digit, then any number of pairs of ascending digits, then any number of pairs of equal digits, then any number of pairs of descending digits, then match the first digit again at the very end.






                                                                                                          share|improve this answer























                                                                                                            up vote
                                                                                                            0
                                                                                                            down vote










                                                                                                            up vote
                                                                                                            0
                                                                                                            down vote










                                                                                                            Retina 0.8.2, 52 bytes



                                                                                                            .
                                                                                                            $*1;$&$*1,
                                                                                                            (1+),1
                                                                                                            ,
                                                                                                            ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                                                                                                            Try it online! Link includes test cases. Explanation:



                                                                                                            .
                                                                                                            $*1;$&$*1,


                                                                                                            Convert each digit to unary twice, separated by ;s and terminated by ,s. However, you can then think of the result as the first digit, a ;, then all the pairs of adjacent digits, the digits of each pair separated by , and the pairs separated by ;s, then another ;, then the last digit, then a final ,.



                                                                                                            (1+),1
                                                                                                            ,


                                                                                                            Subtract the pairs of adjacent digits. This leaves ;,; for equal digits and 1s on the greater side for unequal digits. (This could be done as part of the following regex but obviously that wouldn't be so golfy.)



                                                                                                            ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                                                                                                            Match the first digit, then any number of pairs of ascending digits, then any number of pairs of equal digits, then any number of pairs of descending digits, then match the first digit again at the very end.






                                                                                                            share|improve this answer













                                                                                                            Retina 0.8.2, 52 bytes



                                                                                                            .
                                                                                                            $*1;$&$*1,
                                                                                                            (1+),1
                                                                                                            ,
                                                                                                            ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                                                                                                            Try it online! Link includes test cases. Explanation:



                                                                                                            .
                                                                                                            $*1;$&$*1,


                                                                                                            Convert each digit to unary twice, separated by ;s and terminated by ,s. However, you can then think of the result as the first digit, a ;, then all the pairs of adjacent digits, the digits of each pair separated by , and the pairs separated by ;s, then another ;, then the last digit, then a final ,.



                                                                                                            (1+),1
                                                                                                            ,


                                                                                                            Subtract the pairs of adjacent digits. This leaves ;,; for equal digits and 1s on the greater side for unequal digits. (This could be done as part of the following regex but obviously that wouldn't be so golfy.)



                                                                                                            ^(1+);(,1+;)*(,;)*(1+,;)*1,$


                                                                                                            Match the first digit, then any number of pairs of ascending digits, then any number of pairs of equal digits, then any number of pairs of descending digits, then match the first digit again at the very end.







                                                                                                            share|improve this answer












                                                                                                            share|improve this answer



                                                                                                            share|improve this answer










                                                                                                            answered Nov 19 at 17:15









                                                                                                            Neil

                                                                                                            78.1k744175




                                                                                                            78.1k744175






















                                                                                                                up vote
                                                                                                                0
                                                                                                                down vote














                                                                                                                Red, 181 bytes



                                                                                                                func[n][m: last sort copy t: s: form n
                                                                                                                parse t[opt[copy a to m(a: sort unique a)]copy b thru any m
                                                                                                                opt[copy c to end(c: sort/reverse unique c)]](s = rejoin[a b c])and(s/1 = last s)]


                                                                                                                Try it online!



                                                                                                                More readable:



                                                                                                                f: func[n][
                                                                                                                t: s: form n
                                                                                                                m: last sort copy t
                                                                                                                parse t [ opt [ copy a to m (a: sort unique a) ]
                                                                                                                copy b thru any m
                                                                                                                opt [ copy c to end (c: sort/reverse unique c) ]
                                                                                                                ]
                                                                                                                (s = rejoin [ a b c ]) and (s/1 = last s)
                                                                                                                ]





                                                                                                                share|improve this answer

























                                                                                                                  up vote
                                                                                                                  0
                                                                                                                  down vote














                                                                                                                  Red, 181 bytes



                                                                                                                  func[n][m: last sort copy t: s: form n
                                                                                                                  parse t[opt[copy a to m(a: sort unique a)]copy b thru any m
                                                                                                                  opt[copy c to end(c: sort/reverse unique c)]](s = rejoin[a b c])and(s/1 = last s)]


                                                                                                                  Try it online!



                                                                                                                  More readable:



                                                                                                                  f: func[n][
                                                                                                                  t: s: form n
                                                                                                                  m: last sort copy t
                                                                                                                  parse t [ opt [ copy a to m (a: sort unique a) ]
                                                                                                                  copy b thru any m
                                                                                                                  opt [ copy c to end (c: sort/reverse unique c) ]
                                                                                                                  ]
                                                                                                                  (s = rejoin [ a b c ]) and (s/1 = last s)
                                                                                                                  ]





                                                                                                                  share|improve this answer























                                                                                                                    up vote
                                                                                                                    0
                                                                                                                    down vote










                                                                                                                    up vote
                                                                                                                    0
                                                                                                                    down vote










                                                                                                                    Red, 181 bytes



                                                                                                                    func[n][m: last sort copy t: s: form n
                                                                                                                    parse t[opt[copy a to m(a: sort unique a)]copy b thru any m
                                                                                                                    opt[copy c to end(c: sort/reverse unique c)]](s = rejoin[a b c])and(s/1 = last s)]


                                                                                                                    Try it online!



                                                                                                                    More readable:



                                                                                                                    f: func[n][
                                                                                                                    t: s: form n
                                                                                                                    m: last sort copy t
                                                                                                                    parse t [ opt [ copy a to m (a: sort unique a) ]
                                                                                                                    copy b thru any m
                                                                                                                    opt [ copy c to end (c: sort/reverse unique c) ]
                                                                                                                    ]
                                                                                                                    (s = rejoin [ a b c ]) and (s/1 = last s)
                                                                                                                    ]





                                                                                                                    share|improve this answer













                                                                                                                    Red, 181 bytes



                                                                                                                    func[n][m: last sort copy t: s: form n
                                                                                                                    parse t[opt[copy a to m(a: sort unique a)]copy b thru any m
                                                                                                                    opt[copy c to end(c: sort/reverse unique c)]](s = rejoin[a b c])and(s/1 = last s)]


                                                                                                                    Try it online!



                                                                                                                    More readable:



                                                                                                                    f: func[n][
                                                                                                                    t: s: form n
                                                                                                                    m: last sort copy t
                                                                                                                    parse t [ opt [ copy a to m (a: sort unique a) ]
                                                                                                                    copy b thru any m
                                                                                                                    opt [ copy c to end (c: sort/reverse unique c) ]
                                                                                                                    ]
                                                                                                                    (s = rejoin [ a b c ]) and (s/1 = last s)
                                                                                                                    ]






                                                                                                                    share|improve this answer












                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer










                                                                                                                    answered Nov 19 at 19:22









                                                                                                                    Galen Ivanov

                                                                                                                    5,94711032




                                                                                                                    5,94711032






















                                                                                                                        up vote
                                                                                                                        0
                                                                                                                        down vote













                                                                                                                        Powershell, 77 bytes





                                                                                                                        ($x=-join("$($args|%{"-$_;$_"})"|iex))-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1]


                                                                                                                        Less golfed test script:



                                                                                                                        $f = {
                                                                                                                        # $args = 1,2,3,3,3,2,1
                                                                                                                        $a=$args|%{"-$_;$_"} # "-1;1","-2;2","-3;3","-3;3","-3;3","-2;2","-1;1"
                                                                                                                        $d="$a" # "-1;1 -2;2 -3;3 -3;3 -3;3 -2;2 -1;1"
                                                                                                                        $x=-join($d|Invoke-Expression) # "-1-1-100111"
                                                                                                                        $x-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1] # $true or $false

                                                                                                                        }

                                                                                                                        @(
                                                                                                                        ,($True , 1,2,3,2,1 )
                                                                                                                        ,($True , 1,2,3,3,3,2,1 )
                                                                                                                        ,($True , 9,9 )
                                                                                                                        ,($True , 3 )
                                                                                                                        ,($True , 2,3,4,5,6,7,9,9,2 )
                                                                                                                        ,($False, 1,2,3,2 )
                                                                                                                        ,($False, 7,7,8,8,9,6 )
                                                                                                                        ,($False, 2,3,2,3,2 )
                                                                                                                        ,($False, 4,5,5,6,6,5,5,4 )
                                                                                                                        ,($False, 5,6,4,5 )
                                                                                                                        ) | % {
                                                                                                                        $expected,$a = $_
                                                                                                                        $result = &$f @a
                                                                                                                        "$($result-eq$expected): $result"
                                                                                                                        }


                                                                                                                        Output:



                                                                                                                        True: True
                                                                                                                        True: True
                                                                                                                        True: True
                                                                                                                        True: True
                                                                                                                        True: True
                                                                                                                        True: False
                                                                                                                        True: False
                                                                                                                        True: False
                                                                                                                        True: False
                                                                                                                        True: False





                                                                                                                        share|improve this answer



























                                                                                                                          up vote
                                                                                                                          0
                                                                                                                          down vote













                                                                                                                          Powershell, 77 bytes





                                                                                                                          ($x=-join("$($args|%{"-$_;$_"})"|iex))-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1]


                                                                                                                          Less golfed test script:



                                                                                                                          $f = {
                                                                                                                          # $args = 1,2,3,3,3,2,1
                                                                                                                          $a=$args|%{"-$_;$_"} # "-1;1","-2;2","-3;3","-3;3","-3;3","-2;2","-1;1"
                                                                                                                          $d="$a" # "-1;1 -2;2 -3;3 -3;3 -3;3 -2;2 -1;1"
                                                                                                                          $x=-join($d|Invoke-Expression) # "-1-1-100111"
                                                                                                                          $x-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1] # $true or $false

                                                                                                                          }

                                                                                                                          @(
                                                                                                                          ,($True , 1,2,3,2,1 )
                                                                                                                          ,($True , 1,2,3,3,3,2,1 )
                                                                                                                          ,($True , 9,9 )
                                                                                                                          ,($True , 3 )
                                                                                                                          ,($True , 2,3,4,5,6,7,9,9,2 )
                                                                                                                          ,($False, 1,2,3,2 )
                                                                                                                          ,($False, 7,7,8,8,9,6 )
                                                                                                                          ,($False, 2,3,2,3,2 )
                                                                                                                          ,($False, 4,5,5,6,6,5,5,4 )
                                                                                                                          ,($False, 5,6,4,5 )
                                                                                                                          ) | % {
                                                                                                                          $expected,$a = $_
                                                                                                                          $result = &$f @a
                                                                                                                          "$($result-eq$expected): $result"
                                                                                                                          }


                                                                                                                          Output:



                                                                                                                          True: True
                                                                                                                          True: True
                                                                                                                          True: True
                                                                                                                          True: True
                                                                                                                          True: True
                                                                                                                          True: False
                                                                                                                          True: False
                                                                                                                          True: False
                                                                                                                          True: False
                                                                                                                          True: False





                                                                                                                          share|improve this answer

























                                                                                                                            up vote
                                                                                                                            0
                                                                                                                            down vote










                                                                                                                            up vote
                                                                                                                            0
                                                                                                                            down vote









                                                                                                                            Powershell, 77 bytes





                                                                                                                            ($x=-join("$($args|%{"-$_;$_"})"|iex))-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1]


                                                                                                                            Less golfed test script:



                                                                                                                            $f = {
                                                                                                                            # $args = 1,2,3,3,3,2,1
                                                                                                                            $a=$args|%{"-$_;$_"} # "-1;1","-2;2","-3;3","-3;3","-3;3","-2;2","-1;1"
                                                                                                                            $d="$a" # "-1;1 -2;2 -3;3 -3;3 -3;3 -2;2 -1;1"
                                                                                                                            $x=-join($d|Invoke-Expression) # "-1-1-100111"
                                                                                                                            $x-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1] # $true or $false

                                                                                                                            }

                                                                                                                            @(
                                                                                                                            ,($True , 1,2,3,2,1 )
                                                                                                                            ,($True , 1,2,3,3,3,2,1 )
                                                                                                                            ,($True , 9,9 )
                                                                                                                            ,($True , 3 )
                                                                                                                            ,($True , 2,3,4,5,6,7,9,9,2 )
                                                                                                                            ,($False, 1,2,3,2 )
                                                                                                                            ,($False, 7,7,8,8,9,6 )
                                                                                                                            ,($False, 2,3,2,3,2 )
                                                                                                                            ,($False, 4,5,5,6,6,5,5,4 )
                                                                                                                            ,($False, 5,6,4,5 )
                                                                                                                            ) | % {
                                                                                                                            $expected,$a = $_
                                                                                                                            $result = &$f @a
                                                                                                                            "$($result-eq$expected): $result"
                                                                                                                            }


                                                                                                                            Output:



                                                                                                                            True: True
                                                                                                                            True: True
                                                                                                                            True: True
                                                                                                                            True: True
                                                                                                                            True: True
                                                                                                                            True: False
                                                                                                                            True: False
                                                                                                                            True: False
                                                                                                                            True: False
                                                                                                                            True: False





                                                                                                                            share|improve this answer














                                                                                                                            Powershell, 77 bytes





                                                                                                                            ($x=-join("$($args|%{"-$_;$_"})"|iex))-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1]


                                                                                                                            Less golfed test script:



                                                                                                                            $f = {
                                                                                                                            # $args = 1,2,3,3,3,2,1
                                                                                                                            $a=$args|%{"-$_;$_"} # "-1;1","-2;2","-3;3","-3;3","-3;3","-2;2","-1;1"
                                                                                                                            $d="$a" # "-1;1 -2;2 -3;3 -3;3 -3;3 -2;2 -1;1"
                                                                                                                            $x=-join($d|Invoke-Expression) # "-1-1-100111"
                                                                                                                            $x-match'^(-d)+0*d+$'-and$x[1]-eq$x[-1] # $true or $false

                                                                                                                            }

                                                                                                                            @(
                                                                                                                            ,($True , 1,2,3,2,1 )
                                                                                                                            ,($True , 1,2,3,3,3,2,1 )
                                                                                                                            ,($True , 9,9 )
                                                                                                                            ,($True , 3 )
                                                                                                                            ,($True , 2,3,4,5,6,7,9,9,2 )
                                                                                                                            ,($False, 1,2,3,2 )
                                                                                                                            ,($False, 7,7,8,8,9,6 )
                                                                                                                            ,($False, 2,3,2,3,2 )
                                                                                                                            ,($False, 4,5,5,6,6,5,5,4 )
                                                                                                                            ,($False, 5,6,4,5 )
                                                                                                                            ) | % {
                                                                                                                            $expected,$a = $_
                                                                                                                            $result = &$f @a
                                                                                                                            "$($result-eq$expected): $result"
                                                                                                                            }


                                                                                                                            Output:



                                                                                                                            True: True
                                                                                                                            True: True
                                                                                                                            True: True
                                                                                                                            True: True
                                                                                                                            True: True
                                                                                                                            True: False
                                                                                                                            True: False
                                                                                                                            True: False
                                                                                                                            True: False
                                                                                                                            True: False






                                                                                                                            share|improve this answer














                                                                                                                            share|improve this answer



                                                                                                                            share|improve this answer








                                                                                                                            edited Nov 19 at 20:02

























                                                                                                                            answered Nov 19 at 19:57









                                                                                                                            mazzy

                                                                                                                            1,817313




                                                                                                                            1,817313






















                                                                                                                                up vote
                                                                                                                                0
                                                                                                                                down vote














                                                                                                                                C# (Visual C# Interactive Compiler), 161 bytes





                                                                                                                                s=>{var m=s.OrderBy(c=>c).Last();return s[0]==s.Last()&Enumerable.Range(1,s.Length-1).All(i=>i>s.LastIndexOf(m)?s[i-1]>s[i]:i>s.IndexOf(m)?m==s[i]:s[i-1]<s[i]);}


                                                                                                                                Try it online!



                                                                                                                                Here is an overview of how this works...




                                                                                                                                1. Input is in the form of a string

                                                                                                                                2. Find the largest digit

                                                                                                                                3. Ensure the first and last digits are the same

                                                                                                                                4. Ensure digits after the last occurrence of the largest digit are decreasing

                                                                                                                                5. Ensure digits between the first and last occurrence of the largest digit are equal to the largest digit

                                                                                                                                6. Ensure digits before the first occurrence of the largest digit are increasing






                                                                                                                                share|improve this answer



























                                                                                                                                  up vote
                                                                                                                                  0
                                                                                                                                  down vote














                                                                                                                                  C# (Visual C# Interactive Compiler), 161 bytes





                                                                                                                                  s=>{var m=s.OrderBy(c=>c).Last();return s[0]==s.Last()&Enumerable.Range(1,s.Length-1).All(i=>i>s.LastIndexOf(m)?s[i-1]>s[i]:i>s.IndexOf(m)?m==s[i]:s[i-1]<s[i]);}


                                                                                                                                  Try it online!



                                                                                                                                  Here is an overview of how this works...




                                                                                                                                  1. Input is in the form of a string

                                                                                                                                  2. Find the largest digit

                                                                                                                                  3. Ensure the first and last digits are the same

                                                                                                                                  4. Ensure digits after the last occurrence of the largest digit are decreasing

                                                                                                                                  5. Ensure digits between the first and last occurrence of the largest digit are equal to the largest digit

                                                                                                                                  6. Ensure digits before the first occurrence of the largest digit are increasing






                                                                                                                                  share|improve this answer

























                                                                                                                                    up vote
                                                                                                                                    0
                                                                                                                                    down vote










                                                                                                                                    up vote
                                                                                                                                    0
                                                                                                                                    down vote










                                                                                                                                    C# (Visual C# Interactive Compiler), 161 bytes





                                                                                                                                    s=>{var m=s.OrderBy(c=>c).Last();return s[0]==s.Last()&Enumerable.Range(1,s.Length-1).All(i=>i>s.LastIndexOf(m)?s[i-1]>s[i]:i>s.IndexOf(m)?m==s[i]:s[i-1]<s[i]);}


                                                                                                                                    Try it online!



                                                                                                                                    Here is an overview of how this works...




                                                                                                                                    1. Input is in the form of a string

                                                                                                                                    2. Find the largest digit

                                                                                                                                    3. Ensure the first and last digits are the same

                                                                                                                                    4. Ensure digits after the last occurrence of the largest digit are decreasing

                                                                                                                                    5. Ensure digits between the first and last occurrence of the largest digit are equal to the largest digit

                                                                                                                                    6. Ensure digits before the first occurrence of the largest digit are increasing






                                                                                                                                    share|improve this answer















                                                                                                                                    C# (Visual C# Interactive Compiler), 161 bytes





                                                                                                                                    s=>{var m=s.OrderBy(c=>c).Last();return s[0]==s.Last()&Enumerable.Range(1,s.Length-1).All(i=>i>s.LastIndexOf(m)?s[i-1]>s[i]:i>s.IndexOf(m)?m==s[i]:s[i-1]<s[i]);}


                                                                                                                                    Try it online!



                                                                                                                                    Here is an overview of how this works...




                                                                                                                                    1. Input is in the form of a string

                                                                                                                                    2. Find the largest digit

                                                                                                                                    3. Ensure the first and last digits are the same

                                                                                                                                    4. Ensure digits after the last occurrence of the largest digit are decreasing

                                                                                                                                    5. Ensure digits between the first and last occurrence of the largest digit are equal to the largest digit

                                                                                                                                    6. Ensure digits before the first occurrence of the largest digit are increasing







                                                                                                                                    share|improve this answer














                                                                                                                                    share|improve this answer



                                                                                                                                    share|improve this answer








                                                                                                                                    edited Nov 20 at 16:08

























                                                                                                                                    answered Nov 20 at 12:20









                                                                                                                                    dana

                                                                                                                                    1714




                                                                                                                                    1714






















                                                                                                                                        up vote
                                                                                                                                        0
                                                                                                                                        down vote














                                                                                                                                        Python 3, 114 bytes





                                                                                                                                        def f(r):
                                                                                                                                        l=[*r]
                                                                                                                                        for i in-1,0:
                                                                                                                                        while 1<len(l)and l[i]<l[(1,-2)[i]]:l.pop(i)
                                                                                                                                        return 2>len({*l})and r[0]==r[-1]


                                                                                                                                        Try it online!



                                                                                                                                        Way longer than some Python 2 solutions, but this one is def-based and I like it.






                                                                                                                                        share|improve this answer

























                                                                                                                                          up vote
                                                                                                                                          0
                                                                                                                                          down vote














                                                                                                                                          Python 3, 114 bytes





                                                                                                                                          def f(r):
                                                                                                                                          l=[*r]
                                                                                                                                          for i in-1,0:
                                                                                                                                          while 1<len(l)and l[i]<l[(1,-2)[i]]:l.pop(i)
                                                                                                                                          return 2>len({*l})and r[0]==r[-1]


                                                                                                                                          Try it online!



                                                                                                                                          Way longer than some Python 2 solutions, but this one is def-based and I like it.






                                                                                                                                          share|improve this answer























                                                                                                                                            up vote
                                                                                                                                            0
                                                                                                                                            down vote










                                                                                                                                            up vote
                                                                                                                                            0
                                                                                                                                            down vote










                                                                                                                                            Python 3, 114 bytes





                                                                                                                                            def f(r):
                                                                                                                                            l=[*r]
                                                                                                                                            for i in-1,0:
                                                                                                                                            while 1<len(l)and l[i]<l[(1,-2)[i]]:l.pop(i)
                                                                                                                                            return 2>len({*l})and r[0]==r[-1]


                                                                                                                                            Try it online!



                                                                                                                                            Way longer than some Python 2 solutions, but this one is def-based and I like it.






                                                                                                                                            share|improve this answer













                                                                                                                                            Python 3, 114 bytes





                                                                                                                                            def f(r):
                                                                                                                                            l=[*r]
                                                                                                                                            for i in-1,0:
                                                                                                                                            while 1<len(l)and l[i]<l[(1,-2)[i]]:l.pop(i)
                                                                                                                                            return 2>len({*l})and r[0]==r[-1]


                                                                                                                                            Try it online!



                                                                                                                                            Way longer than some Python 2 solutions, but this one is def-based and I like it.







                                                                                                                                            share|improve this answer












                                                                                                                                            share|improve this answer



                                                                                                                                            share|improve this answer










                                                                                                                                            answered Nov 20 at 16:59









                                                                                                                                            etene

                                                                                                                                            4487




                                                                                                                                            4487






















                                                                                                                                                up vote
                                                                                                                                                0
                                                                                                                                                down vote














                                                                                                                                                Ruby, 47 bytes





                                                                                                                                                ->n{(r=n.each_cons(2).map{|a,b|a<=>b})==r.sort}


                                                                                                                                                Try it online!



                                                                                                                                                Input as array of digits, output is boolean.






                                                                                                                                                share|improve this answer

























                                                                                                                                                  up vote
                                                                                                                                                  0
                                                                                                                                                  down vote














                                                                                                                                                  Ruby, 47 bytes





                                                                                                                                                  ->n{(r=n.each_cons(2).map{|a,b|a<=>b})==r.sort}


                                                                                                                                                  Try it online!



                                                                                                                                                  Input as array of digits, output is boolean.






                                                                                                                                                  share|improve this answer























                                                                                                                                                    up vote
                                                                                                                                                    0
                                                                                                                                                    down vote










                                                                                                                                                    up vote
                                                                                                                                                    0
                                                                                                                                                    down vote










                                                                                                                                                    Ruby, 47 bytes





                                                                                                                                                    ->n{(r=n.each_cons(2).map{|a,b|a<=>b})==r.sort}


                                                                                                                                                    Try it online!



                                                                                                                                                    Input as array of digits, output is boolean.






                                                                                                                                                    share|improve this answer













                                                                                                                                                    Ruby, 47 bytes





                                                                                                                                                    ->n{(r=n.each_cons(2).map{|a,b|a<=>b})==r.sort}


                                                                                                                                                    Try it online!



                                                                                                                                                    Input as array of digits, output is boolean.







                                                                                                                                                    share|improve this answer












                                                                                                                                                    share|improve this answer



                                                                                                                                                    share|improve this answer










                                                                                                                                                    answered 17 hours ago









                                                                                                                                                    G B

                                                                                                                                                    7,5561328




                                                                                                                                                    7,5561328






























                                                                                                                                                         

                                                                                                                                                        draft saved


                                                                                                                                                        draft discarded



















































                                                                                                                                                         


                                                                                                                                                        draft saved


                                                                                                                                                        draft discarded














                                                                                                                                                        StackExchange.ready(
                                                                                                                                                        function () {
                                                                                                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176224%2fis-this-number-a-hill-number%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

                                                                                                                                                        Plaza Victoria

                                                                                                                                                        In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                                                                                                                                                        How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...