# My source is in order, is yours?

Your challenge is to write a program, function, etc. that calculates if the passed string is "in order". That means that the characters of the string have character codes that are in order from smallest to largest. The smallest char code must be the first. By that I mean lowest unicode codepoints to highest. It doesn't matter what code page you language uses.

You must return one value if the input is "in order" and another if it is not. The values must be distinct, but there is no other restriction on the output values. For example, you may print/return/output true for !1AQaq¡± (in order) and false for aq!QA. The two distinct values don't need to be truthy or falsy or anything like that, just two distinct values. Repeated strings (eg. aa) are in order.

You only need to support up to unicode U+007E (~) (ascii 126)

However, the characters of your program must itself be in order. Good luck and happy ing!

• You don't need to have truthy/falsy values? two truthys would work? – Rɪᴋᴇʀ Apr 13 '17 at 22:14
• Also, is the smallest char code always at the first char? Or can it be reversed? – Rɪᴋᴇʀ Apr 13 '17 at 22:14
• Code-golf honestly seems like a poor win condition for this form of restricted source. Code bowling for most unique characters would be more interesting. – fəˈnɛtɪk Apr 13 '17 at 22:50
• @Pavel Pop cons don't work well for achieving a particular task in a particular way. – Dennis Apr 14 '17 at 1:02
• is repeated string in order? for example, is "aa" in order? – tsh Apr 14 '17 at 3:05

# Brachylog, 2 bytes

.o


Try it online!

## Explanation

.o
.   Assert that {the input} equals the output of the last command in the program
o  Sort {the input}


As a full program, an assertion failure gives false., any successful run that doesn't violate any assertions gives true.

# Jelly, 2 bytes

Ṣ⁼


Try it online!

## Explanation

Ṣ⁼
Ṣ    Sort {the input}
⁼   Compare that to {the input} for equality of the whole structure


⁼Ṣ also has the right functionality ("compare the input to the sorted input"), so it was just a case of running the two programs on themselves to figure out which was in order (I certainly don't have the Unicode codepoints of this part of Jelly's weird character set memorized).

• Your submission is wrong in Jelly encoding, it needs to be ⁼Ṣ instead. You can see Jelly's codepage here. – Erik the Outgolfer Apr 14 '17 at 8:33
• @EriktheOutgolfer That is easily fixed; ⁼Ṣ does exactly the same as Ṣ⁼. – steenbergh Apr 14 '17 at 10:50
• @steenbergh This submission, as it is right now, is invalid. Even though the fix is easy, it hasn't been applied yet, and it's discouraged for others to edit code. – Erik the Outgolfer Apr 14 '17 at 10:51
• @EriktheOutgolfer Discussion about this answer is mainly about which codepage to use: the challenge references Unicode (though doesn't explicitly tell us to use it) and Jelly has its own codepage. Whatever the outcome, fixing this answer is trivial. Therefor, I wouldn't go as far as calling this answer 'invalid' - I wouldn't even downvote it in its current state. – steenbergh Apr 14 '17 at 10:59
• @steenbergh I haven't downvoted either, I was just notifying ais523 :) – Erik the Outgolfer Apr 14 '17 at 11:00

# 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


# 05AB1E, 3 bytes

D{å


Try it online!

Explanation:

D     Duplicate stack
{    Sort the copy
å   Check if the sorted copy is a substring of the original
This will only return 1 if the original input is sorted, 0 otherwise.

• D{Q also works... – Neil A. May 17 '17 at 21:44
• @NeilA.It might do the same, but the characters are not in order. Requirement is that your source code passes the same test as the data does. This should yield 1. – steenbergh May 18 '17 at 5:48

# Pyke, 2 bytes

Sq


Try it online!

S  - sorted(input)
q - ^ == input


# 2sable, 2 bytes

{Ê


Try it online!

Explanation

{    # sorted input
Ê   # not equals (implicit input)


Outputs 0 if it is order, else 1.

• @steenbergh: Ah, missed that part of the challenge. – Emigna Apr 14 '17 at 12:08
• @steenbergh: Fixed! Fortunately we could output any distinct values :) – Emigna Apr 14 '17 at 12:13

# Pyth, 2 bytes

<S


False means sorted, True means unsorted.

Test suite

This was fairly nontrivial to come up with. The most obvious solution to this problem, without the restricted source, is SI, invariant under sorting. But that's not sorted. Then I thought of qS, which implicitly uses the input variable twice, checking if it's equal to its sorted self. But while q < s, q > S, so this didn't work either. But < comes before S, and the only way that the sorted version can not be less than the original is if the original was sorted, since the sorted version is the lexicographically minimal permutation of the elements.

# CGL (CGL Golfing Language), 4 bytes (non-competing)

-:Sc


Explanation:

- Decrement the stack counter so the current stack is where input is put
: Split the first element of the current stack (input) into an array of single strings, make that the next stack, and increment the stack counter
S Sort the current stack
c Compare the current stack and the one before, push that to the next stack and increment the stack counter
(implicit) Output the first element of the current stack, true if in order, false if not.


Non-competing because :, S, and c were implemented after the creation of this challenge.

• Is there proof that this language was created before this challenge? – Kritixi Lithos Apr 14 '17 at 12:33
• @KritixiLithos yes, and it is technically a valid language, but I will make this non-competing because the functions necessary to complete this were made after this challenge. CGL is still a work in progress, and I am using challenges to show me what new functions should be added. – programmer5000 Apr 14 '17 at 12:51