Skip to main content
Commonmark migration
Source Link

MATL, 12 bytes

dZSd1<AGds~*

Try it online!

###Explanation

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

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

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).
Better way to process test cases in MATL.
Source Link
Sanchises
  • 9.5k
  • 1
  • 36
  • 61

MATL, 12 bytes

dZSd1<AGds~*

Try it online!

(note: the TIO version uses H instead of G to process all test cases at once.)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<A1<          % A number is a hill number if `A`ll 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).

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

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).
added 51 characters in body
Source Link
Sanchises
  • 9.5k
  • 1
  • 36
  • 61

MATL, 1412 bytes

dZSd1<AH5L)d~*dZSd1<AGds~*

Try it online! 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.
       G5L)Gds      % Push the input, selectand firstsum andall lastthe elementdifferences.
          ~ d~    % Negate the difference between these elements.
           *  *  % Multiply the two tests (=logical AND).

MATL, 14 bytes

dZSd1<AH5L)d~*

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.

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.
       G5L)     % Push the input, select first and last element
           d~   % Negate the difference between these elements.
             *  % Multiply the two tests (=logical AND).

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).
Source Link
Sanchises
  • 9.5k
  • 1
  • 36
  • 61
Loading