Is everything in order?

14

1

Challenge:

Input: a string, consisting of only printable ASCII characters
Output: a truthy/falsey value whether its characters are in alphabetical order (based on their UTF-8 unicode values), from any starting point inside the string including wrap-around by going left-to-right

For example: xyzabc would give a truthy result, because we could travel a→b→c→x→y→z, but xzy would give a falsey result, because all possible starting points (x→y→z; y→z→x; z→x→y) are not in the correct order.

This sounds pretty simple, right? But there is one catch, as this is a challenge: your program/function has to be in the correct order as well.

†: Based on the order of the characters in your own codepage. i.e. a program written in Jelly need to be (with the wraparound of course) in the order of its own codepage, instead of UTF-8 order.

Challenge rules:

  • The input can be in any reasonable format. Can be a string, read from STDIN, a list of characters, etc. (No, you are not allowed to take a list of unicode values - which would basically be an integer list - unless your language does this conversion by default (i.e. Java (char only), Whitespace, etc.)
  • The input is guaranteed to be printable ASCII (range \$[32,126]\$ / [' ','~']).
  • If your program/function is written in a different codepage, it does not necessary have to hold a truthy value when used as input for itself. The source code does need to be in the correct order based on the used codepage of course.
  • The input is guaranteed to be non-empty. (An input of one or two characters will always result in a truthy output.)
  • The input (and your source) can contain multiple of the same characters.
  • This is , for which the longest answer counting only distinct bytes wins (i.e. if your source code is ABBCabbc1223 your score would be 9 for 123ABCabc).

General rules:

  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code (i.e. TIO).
  • Also, adding an explanation for your answer is highly recommended.

Test cases:

Truthy:

~
ab
ba
```
*5a
Test
test
xyzabc
aaabbbccc
aaabbbCCC
AAAbbbccc
msuwy !#),-./0123:;<?@BCFGILMNOQTWX]^_bf
oqqx}}~#$'''*+-./33489=?ABCHLQQQRTW[\]^_abcfgjkklmnno

Falsey:

xzy
C-U
TeSt
tesT
aaaBBBccc
M3"b=J7Uh:kg&F~\p`GLx?9#!%XCOZBv.m_)Y4V*

Kevin Cruijssen

Posted 2020-01-20T12:25:12.057

Reputation: 67 575

related – Kevin Cruijssen – 2020-01-20T12:25:21.990

7IMHO I find it a bit too bad that a single rule disallows per se most programming languages and allows only cryptic-characters-languages-created-only-for-golfing, it could be more open by for example counting the longest ordered sequence in the code. (But that would mean not counting commented characters to prevent having the whole alphabet as a comment, even if that would damage a bit current aswer) – Kaddath – 2020-01-21T13:57:53.257

1

@Kaddath I can understand your standpoint and kinda agree, but I don't think banning comments would help, since we don't have a clear definition of what a comment is. The current 05AB1E for example doesn't use any comments (in fact, the language doesn't even have comments), although there are still loads of no-ops which cancel each other out so only the code functionality remains. And not allowing no-ops kinda defeats the [code-bowling] part tbh.

– Kevin Cruijssen – 2020-01-22T07:42:58.267

I'm willing to change the challenge to allow more answers (if Grimmy agrees), but it should require a clear definition of what is and isn't allowed. Currently I'm thinking of only allowing the 256 default characters of the used code-page perhaps (extended ASCII for most languages), so 256 would be the maximum score, and you can't for example score 137,929 by using all existing characters in for example a Lenguage/Unary answer. And comments are then still allowed. But not sure if that's a good solution.

– Kevin Cruijssen – 2020-01-22T07:46:25.977

1(if Grimmy agrees) I do. (Note that 256 is already the maximum score, since score is the number of distinct bytes). – Grimmy – 2020-01-22T14:38:32.100

@Grimmy Thanks for agreeing, but I'm still not really sure how to change the challenge. If I add that you have to maximize the largest portion of your used code page in your source code, everyone would just put all 256 bytes after one-another in a comment.. I.e. (used ASCII only as example) the source code # !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~. I could ban comments, but what counts as a comment in that case? "this is a comment"\ is what I sometimes add in my 05AB1E answers, but it's not really a comment.. Where to draw the line. – Kevin Cruijssen – 2020-01-22T17:47:45.763

Answers

10

05AB1E, 10 ... 172 distinct bytes

\]^_abcdefghiijklmnopqrstuvwxyz{|}}}~ƵƵ€Λ‚„…†‡ˆ‰ŠĆĆĆŽƶĀ‘‘’’““””••–—™š›œćŸā¡¢¢¢¤¤¦§¨©ª«¬®¯°±´¶·¸º»¼½½¾¿ÀÁÁÂÃÄÅÇÌÍÐÐÐÐÐÐÑÒÓÔÕÖ×ØÙÚÛÜÝßàáâãäåçèéêëìíîïðñòóôõö÷úü
 -.0123456789;<>@ABCDDDHKKOPQRSTUVWXYZ

Try it online! or validate all test cases (note: the "all test cases" version omits ] and ë, since those don't play well with the header and footer required to run the code repeatedly).

Uses the 05AB1E code page. Validate restricted-source and scoring.

The useful code is just:

Ć            # append the first character of the input to the input
 Ç           # convert to a list of codepoints
  ü-         # pairwise subtraction
    1@       # >= 1?
      D      # duplicate
       O     # sum
        Q    # equal?
         Z   # maximum

The rest amounts to NOOPs.

Grimmy

Posted 2020-01-20T12:25:12.057

Reputation: 12 521

1

Nice answer. I wasn't expecting that the entire alphabet (except for q) could be used as a no-op like that. :) And I've verified that it's indeed correct for 05AB1E's codepage, but you may want to explicitly mention it uses the custom 05AB1E codepage for challenges like this. Btw, you can add a few more no-ops between the Q and Z, like R and S for example, as well as UX or VY. :)

– Kevin Cruijssen – 2020-01-20T13:33:11.673

Actually q can be used as well, since it's within a non-executed i} anyway. And yeah, I'm not done bowling, there's still a ton of bytes to add. – Grimmy – 2020-01-20T13:39:01.390

1@KevinCruijssen I'm done with the low-hanging fruits. Of the 96 missing bytes, 46 are the bytes between ü and -, which can't be separated except by whitespace. – Grimmy – 2020-01-20T16:21:31.330