Skip to main content
3 of 4
Better way to process test cases in MATL.
Sanchises
  • 9.5k
  • 1
  • 36
  • 61

MATL, 12 bytes

dZSd1<AGds~*

Try it online!

###Explanation

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

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