Skip to main content
added 214 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 5 bytes

GGS\a 

Outputs 0 if input is in order, 1 otherwise.

Try it online!

Explanation

This sorts the input and computes the modulo operationmodulus of (the code points of) each char from the input with that at the same index in the sorted input. The input is sortedin order if and only if all results are 0.

For example, consider the input string BCD!. Sorting it gives '!BCD. The arrays of code points are respectively [66 67 68 33] and [33 66 67 68]. Computing the moduli gives [0 1 1 33], so the input is not in order. Note how some results can be 0 even if the values were not the same (here that happens at the first position), but that cannot happen in all entries unless the input is in order.

G % Push input string GS % Push input string and sort it \ % ModuloModulus, element-wise. This gives all zeros iff the input was in order a % Any: gives 1 if any entry is non-zero. Implicitly display 

MATL, 5 bytes

GGS\a 

Outputs 0 if in order, 1 otherwise.

Try it online!

Explanation

This sorts the input and computes the modulo operation of (the code points of) each char from the input with that at the same index in the sorted input. The input is sorted if and only if all results are 0.

G % Push input string GS % Push input string and sort it \ % Modulo, element-wise. This gives all zeros iff the input was in order a % Any: gives 1 if any entry is non-zero. Implicitly display 

MATL, 5 bytes

GGS\a 

Outputs 0 if input is in order, 1 otherwise.

Try it online!

Explanation

This computes the modulus of (the code points of) each char from the input with that at the same index in the sorted input. The input is in order if and only if all results are 0.

For example, consider the input string BCD!. Sorting it gives '!BCD. The arrays of code points are respectively [66 67 68 33] and [33 66 67 68]. Computing the moduli gives [0 1 1 33], so the input is not in order. Note how some results can be 0 even if the values were not the same (here that happens at the first position), but that cannot happen in all entries unless the input is in order.

G % Push input string GS % Push input string and sort it \ % Modulus, element-wise. This gives all zeros iff the input was in order a % Any: gives 1 if any entry is non-zero. Implicitly display 
added 214 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 5 bytes

GGS\a 

Outputs 0 if in order, 1 otherwise.

Try it online!

Explanation

This sorts the input and computes the modulo operation of (the code points of) each char from the input with that at the same index in the sorted input. The input is sorted if and only if all results are 0.

G % Push input string GS % Push input string and sort it \ % Modulo, element-wise. This gives all zeros iff the input was in order a % Any: gives 1 if any entry is non-zero. Implicitly display 

MATL, 5 bytes

GGS\a 

Outputs 0 if in order, 1 otherwise.

Try it online!

Explanation

G % Push input string GS % Push input string and sort it \ % Modulo, element-wise. This gives all zeros iff the input was in order a % Any: gives 1 if any entry is non-zero. Implicitly display 

MATL, 5 bytes

GGS\a 

Outputs 0 if in order, 1 otherwise.

Try it online!

Explanation

This sorts the input and computes the modulo operation of (the code points of) each char from the input with that at the same index in the sorted input. The input is sorted if and only if all results are 0.

G % Push input string GS % Push input string and sort it \ % Modulo, element-wise. This gives all zeros iff the input was in order a % Any: gives 1 if any entry is non-zero. Implicitly display 
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 5 bytes

GGS\a 

Outputs 0 if in order, 1 otherwise.

Try it online!

Explanation

G % Push input string GS % Push input string and sort it \ % Modulo, element-wise. This gives all zeros iff the input was in order a % Any: gives 1 if any entry is non-zero. Implicitly display