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 restricted-source 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 code-bowlingcode-challenge, for which the longest answer counting only distinct bytes wins (i.e. if your source code is
ABBCabbc1223
your score would be 9 for123ABCabc
).
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*
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
– Kevin Cruijssen – 2020-01-22T07:42:58.267[code-bowling]
part tbh.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.9771
(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