Is this number a hill number?











up vote
16
down vote

favorite
1












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.


    • Taking input as a list of digits is not considered reasonable.



  • 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
    23 hours ago










  • 222222222 is a hill number, largest digit is 2 and thus can be repeated
    – u_ndefined
    1 hour ago












  • Is a string reasonable?
    – Sanchises
    1 hour ago










  • @Sanchises yes, but list of chars is not
    – u_ndefined
    1 hour ago










  • @frarugi87 See comment above.
    – Dennis
    1 hour ago















up vote
16
down vote

favorite
1












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.


    • Taking input as a list of digits is not considered reasonable.



  • 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
    23 hours ago










  • 222222222 is a hill number, largest digit is 2 and thus can be repeated
    – u_ndefined
    1 hour ago












  • Is a string reasonable?
    – Sanchises
    1 hour ago










  • @Sanchises yes, but list of chars is not
    – u_ndefined
    1 hour ago










  • @frarugi87 See comment above.
    – Dennis
    1 hour ago













up vote
16
down vote

favorite
1









up vote
16
down vote

favorite
1






1





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.


    • Taking input as a list of digits is not considered reasonable.



  • 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.


    • Taking input as a list of digits is not considered reasonable.



  • 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 1 hour ago

























asked yesterday









u_ndefined

59913




59913








  • 5




    What about 222222222? Is it a flat hill number?
    – frarugi87
    23 hours ago










  • 222222222 is a hill number, largest digit is 2 and thus can be repeated
    – u_ndefined
    1 hour ago












  • Is a string reasonable?
    – Sanchises
    1 hour ago










  • @Sanchises yes, but list of chars is not
    – u_ndefined
    1 hour ago










  • @frarugi87 See comment above.
    – Dennis
    1 hour ago














  • 5




    What about 222222222? Is it a flat hill number?
    – frarugi87
    23 hours ago










  • 222222222 is a hill number, largest digit is 2 and thus can be repeated
    – u_ndefined
    1 hour ago












  • Is a string reasonable?
    – Sanchises
    1 hour ago










  • @Sanchises yes, but list of chars is not
    – u_ndefined
    1 hour ago










  • @frarugi87 See comment above.
    – Dennis
    1 hour ago








5




5




What about 222222222? Is it a flat hill number?
– frarugi87
23 hours ago




What about 222222222? Is it a flat hill number?
– frarugi87
23 hours ago












222222222 is a hill number, largest digit is 2 and thus can be repeated
– u_ndefined
1 hour ago






222222222 is a hill number, largest digit is 2 and thus can be repeated
– u_ndefined
1 hour ago














Is a string reasonable?
– Sanchises
1 hour ago




Is a string reasonable?
– Sanchises
1 hour ago












@Sanchises yes, but list of chars is not
– u_ndefined
1 hour ago




@Sanchises yes, but list of chars is not
– u_ndefined
1 hour ago












@frarugi87 See comment above.
– Dennis
1 hour ago




@frarugi87 See comment above.
– Dennis
1 hour ago










17 Answers
17






active

oldest

votes

















up vote
6
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
    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













        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
          19 hours ago










        • @Shaggy I wish I could but this is apparently not allowed .
          – Arnauld
          19 hours ago










        • 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
          19 hours ago










        • @J.Doe The OP hasn't confirmed yet if numbers such as 222222222 are hill numbers or not. (If not, I think several answers are going to be invalidated.)
          – Arnauld
          13 hours ago


















        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














          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
            yesterday


















          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
            1
            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
              1
              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
                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













                  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
                    0
                    down vote













                    Mathematica/Wolfram Language, 69 bytes



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



                    Sort[x=Sign[-Differences[y=IntegerDigits[#]]]]==x&&First[y]==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.






                    share|improve this answer





















                    • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                      – Michael Seifert
                      19 hours ago




















                    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














                        MATL, 12 bytes



                        dZSd1<AGds~*


                        Try it online!



                        (note: the TIO version uses H instead of G to process all test cases at once.)



                        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 % A number is a hill number if `A`ll these differences are < 1.
                        Gds % Push the input, and sum all the differences.
                        ~ % Negate
                        * % Multiply the two tests (=logical AND).





                        share|improve this answer






























                          up vote
                          0
                          down vote














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





                          x=>{var s=x+"";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. Convert input int into 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 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





















                              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

























                              17 Answers
                              17






                              active

                              oldest

                              votes








                              17 Answers
                              17






                              active

                              oldest

                              votes









                              active

                              oldest

                              votes






                              active

                              oldest

                              votes








                              up vote
                              6
                              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














                                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










                                  up vote
                                  6
                                  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 22 hours ago

























                                  answered 23 hours ago









                                  Dennis

                                  184k32293729




                                  184k32293729






















                                      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 yesterday









                                          lirtosiast

                                          15.5k436104




                                          15.5k436104






















                                              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 yesterday

























                                                  answered yesterday









                                                  lirtosiast

                                                  15.5k436104




                                                  15.5k436104






















                                                      up vote
                                                      4
                                                      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
                                                        19 hours ago










                                                      • @Shaggy I wish I could but this is apparently not allowed .
                                                        – Arnauld
                                                        19 hours ago










                                                      • 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
                                                        19 hours ago










                                                      • @J.Doe The OP hasn't confirmed yet if numbers such as 222222222 are hill numbers or not. (If not, I think several answers are going to be invalidated.)
                                                        – Arnauld
                                                        13 hours ago















                                                      up vote
                                                      4
                                                      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
                                                        19 hours ago










                                                      • @Shaggy I wish I could but this is apparently not allowed .
                                                        – Arnauld
                                                        19 hours ago










                                                      • 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
                                                        19 hours ago










                                                      • @J.Doe The OP hasn't confirmed yet if numbers such as 222222222 are hill numbers or not. (If not, I think several answers are going to be invalidated.)
                                                        – Arnauld
                                                        13 hours ago













                                                      up vote
                                                      4
                                                      down vote










                                                      up vote
                                                      4
                                                      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 23 hours ago

























                                                      answered yesterday









                                                      Arnauld

                                                      69.2k585293




                                                      69.2k585293












                                                      • You can save 5 bytes by taking input as an array of digits.
                                                        – Shaggy
                                                        19 hours ago










                                                      • @Shaggy I wish I could but this is apparently not allowed .
                                                        – Arnauld
                                                        19 hours ago










                                                      • 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
                                                        19 hours ago










                                                      • @J.Doe The OP hasn't confirmed yet if numbers such as 222222222 are hill numbers or not. (If not, I think several answers are going to be invalidated.)
                                                        – Arnauld
                                                        13 hours ago


















                                                      • You can save 5 bytes by taking input as an array of digits.
                                                        – Shaggy
                                                        19 hours ago










                                                      • @Shaggy I wish I could but this is apparently not allowed .
                                                        – Arnauld
                                                        19 hours ago










                                                      • 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
                                                        19 hours ago










                                                      • @J.Doe The OP hasn't confirmed yet if numbers such as 222222222 are hill numbers or not. (If not, I think several answers are going to be invalidated.)
                                                        – Arnauld
                                                        13 hours ago
















                                                      You can save 5 bytes by taking input as an array of digits.
                                                      – Shaggy
                                                      19 hours ago




                                                      You can save 5 bytes by taking input as an array of digits.
                                                      – Shaggy
                                                      19 hours ago












                                                      @Shaggy I wish I could but this is apparently not allowed .
                                                      – Arnauld
                                                      19 hours ago




                                                      @Shaggy I wish I could but this is apparently not allowed .
                                                      – Arnauld
                                                      19 hours ago












                                                      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
                                                      19 hours ago




                                                      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
                                                      19 hours ago












                                                      @J.Doe The OP hasn't confirmed yet if numbers such as 222222222 are hill numbers or not. (If not, I think several answers are going to be invalidated.)
                                                      – Arnauld
                                                      13 hours ago




                                                      @J.Doe The OP hasn't confirmed yet if numbers such as 222222222 are hill numbers or not. (If not, I think several answers are going to be invalidated.)
                                                      – Arnauld
                                                      13 hours ago










                                                      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 yesterday









                                                          TFeld

                                                          13.5k21139




                                                          13.5k21139






















                                                              up vote
                                                              3
                                                              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
                                                                yesterday















                                                              up vote
                                                              3
                                                              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
                                                                yesterday













                                                              up vote
                                                              3
                                                              down vote










                                                              up vote
                                                              3
                                                              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 yesterday









                                                              nwellnhof

                                                              5,9981123




                                                              5,9981123












                                                              • I was literally seconds away from posting this lol.
                                                                – Jo King
                                                                yesterday


















                                                              • I was literally seconds away from posting this lol.
                                                                – Jo King
                                                                yesterday
















                                                              I was literally seconds away from posting this lol.
                                                              – Jo King
                                                              yesterday




                                                              I was literally seconds away from posting this lol.
                                                              – Jo King
                                                              yesterday










                                                              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 yesterday

























                                                                  answered yesterday









                                                                  Kevin Cruijssen

                                                                  34.1k554181




                                                                  34.1k554181






















                                                                      up vote
                                                                      1
                                                                      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
                                                                        1
                                                                        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
                                                                          1
                                                                          down vote










                                                                          up vote
                                                                          1
                                                                          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 17 hours ago

























                                                                          answered 17 hours ago









                                                                          Jonah

                                                                          1,941816




                                                                          1,941816






















                                                                              up vote
                                                                              1
                                                                              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
                                                                                1
                                                                                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
                                                                                  1
                                                                                  down vote










                                                                                  up vote
                                                                                  1
                                                                                  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 7 hours ago

























                                                                                  answered 14 hours ago









                                                                                  J.Doe

                                                                                  1,961112




                                                                                  1,961112






















                                                                                      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 21 hours ago









                                                                                          Neil

                                                                                          78k744175




                                                                                          78k744175






















                                                                                              up vote
                                                                                              0
                                                                                              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
                                                                                                0
                                                                                                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
                                                                                                  0
                                                                                                  down vote










                                                                                                  up vote
                                                                                                  0
                                                                                                  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 20 hours ago









                                                                                                  Shaggy

                                                                                                  18.1k21663




                                                                                                  18.1k21663






















                                                                                                      up vote
                                                                                                      0
                                                                                                      down vote













                                                                                                      Mathematica/Wolfram Language, 69 bytes



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



                                                                                                      Sort[x=Sign[-Differences[y=IntegerDigits[#]]]]==x&&First[y]==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.






                                                                                                      share|improve this answer





















                                                                                                      • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                        – Michael Seifert
                                                                                                        19 hours ago

















                                                                                                      up vote
                                                                                                      0
                                                                                                      down vote













                                                                                                      Mathematica/Wolfram Language, 69 bytes



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



                                                                                                      Sort[x=Sign[-Differences[y=IntegerDigits[#]]]]==x&&First[y]==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.






                                                                                                      share|improve this answer





















                                                                                                      • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                        – Michael Seifert
                                                                                                        19 hours ago















                                                                                                      up vote
                                                                                                      0
                                                                                                      down vote










                                                                                                      up vote
                                                                                                      0
                                                                                                      down vote









                                                                                                      Mathematica/Wolfram Language, 69 bytes



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



                                                                                                      Sort[x=Sign[-Differences[y=IntegerDigits[#]]]]==x&&First[y]==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.






                                                                                                      share|improve this answer












                                                                                                      Mathematica/Wolfram Language, 69 bytes



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



                                                                                                      Sort[x=Sign[-Differences[y=IntegerDigits[#]]]]==x&&First[y]==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.







                                                                                                      share|improve this answer












                                                                                                      share|improve this answer



                                                                                                      share|improve this answer










                                                                                                      answered 19 hours ago









                                                                                                      Michael Seifert

                                                                                                      1514




                                                                                                      1514












                                                                                                      • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                        – Michael Seifert
                                                                                                        19 hours ago




















                                                                                                      • The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                        – Michael Seifert
                                                                                                        19 hours ago


















                                                                                                      The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                      – Michael Seifert
                                                                                                      19 hours ago






                                                                                                      The fact that IntegerDigits and Differences are rather long function names is a bit annoying.
                                                                                                      – Michael Seifert
                                                                                                      19 hours ago












                                                                                                      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 19 hours ago









                                                                                                          Galen Ivanov

                                                                                                          5,90711032




                                                                                                          5,90711032






















                                                                                                              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 18 hours ago

























                                                                                                                  answered 18 hours ago









                                                                                                                  mazzy

                                                                                                                  1,747313




                                                                                                                  1,747313






















                                                                                                                      up vote
                                                                                                                      0
                                                                                                                      down vote














                                                                                                                      MATL, 12 bytes



                                                                                                                      dZSd1<AGds~*


                                                                                                                      Try it online!



                                                                                                                      (note: the TIO version uses H instead of G to process all test cases at once.)



                                                                                                                      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 % A number is a hill number if `A`ll these differences are < 1.
                                                                                                                      Gds % Push the input, and sum all the differences.
                                                                                                                      ~ % Negate
                                                                                                                      * % Multiply the two tests (=logical AND).





                                                                                                                      share|improve this answer



























                                                                                                                        up vote
                                                                                                                        0
                                                                                                                        down vote














                                                                                                                        MATL, 12 bytes



                                                                                                                        dZSd1<AGds~*


                                                                                                                        Try it online!



                                                                                                                        (note: the TIO version uses H instead of G to process all test cases at once.)



                                                                                                                        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 % A number is a hill number if `A`ll these differences are < 1.
                                                                                                                        Gds % Push the input, and sum all the differences.
                                                                                                                        ~ % Negate
                                                                                                                        * % Multiply the two tests (=logical AND).





                                                                                                                        share|improve this answer

























                                                                                                                          up vote
                                                                                                                          0
                                                                                                                          down vote










                                                                                                                          up vote
                                                                                                                          0
                                                                                                                          down vote










                                                                                                                          MATL, 12 bytes



                                                                                                                          dZSd1<AGds~*


                                                                                                                          Try it online!



                                                                                                                          (note: the TIO version uses H instead of G to process all test cases at once.)



                                                                                                                          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 % A number is a hill number if `A`ll these differences are < 1.
                                                                                                                          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!



                                                                                                                          (note: the TIO version uses H instead of G to process all test cases at once.)



                                                                                                                          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 % A number is a hill number if `A`ll these differences are < 1.
                                                                                                                          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 3 hours ago

























                                                                                                                          answered 3 hours ago









                                                                                                                          Sanchises

                                                                                                                          5,71212351




                                                                                                                          5,71212351






















                                                                                                                              up vote
                                                                                                                              0
                                                                                                                              down vote














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





                                                                                                                              x=>{var s=x+"";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. Convert input int into 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), 172 bytes





                                                                                                                                x=>{var s=x+"";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. Convert input int into 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), 172 bytes





                                                                                                                                  x=>{var s=x+"";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. Convert input int into 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), 172 bytes





                                                                                                                                  x=>{var s=x+"";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. Convert input int into 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 18 mins ago

























                                                                                                                                  answered 2 hours ago









                                                                                                                                  dana

                                                                                                                                  1714




                                                                                                                                  1714






















                                                                                                                                      up vote
                                                                                                                                      0
                                                                                                                                      down vote














                                                                                                                                      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

























                                                                                                                                        up vote
                                                                                                                                        0
                                                                                                                                        down vote














                                                                                                                                        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























                                                                                                                                          up vote
                                                                                                                                          0
                                                                                                                                          down vote










                                                                                                                                          up vote
                                                                                                                                          0
                                                                                                                                          down vote










                                                                                                                                          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, 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










                                                                                                                                          answered 12 mins ago









                                                                                                                                          Dennis

                                                                                                                                          184k32293729




                                                                                                                                          184k32293729






























                                                                                                                                               

                                                                                                                                              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

                                                                                                                                              Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                                                                                                                                              Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                                                                                                                                              A Topological Invariant for $pi_3(U(n))$