Skip to main content
added 73 characters in body
Source Link
Neil
  • 177.2k
  • 20
  • 9

Lexicographically earliest valid UTF-8 byte sequence permutation

There are currently 1,114,112 possible Unicode characters (code points). Each character has a unique valid byte sequence in the UTF-8 encoding. Different characters have different length encodings:

  • ASCII characters have a 1-byte encoding 00-7F.
  • The next 1920 characters have a 2-byte encoding C2 80-DF BF.
  • The rest of the BMP has a 3-byte encoding E0 A0 80-ED 9F BF and EE 80 80-EF BF BF.
  • The other planes have a 4-byte encoding F0 90 80 80-F4 8F BF BF.

It's possible for two strings (specific non-normalised sequences of Unicode code points) of Unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A1 C3 A2) and ¢á (C2 A2 C3 A1).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that finds the string whose UTF-8 byte sequence is lexicographically earliest of all such sequences that are permutations of the UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A2 C3 A1 62 61) your output would be ab¡âᴵ (61 62 C2 A1 C3 A2 E1 B4 B5).

Note however that some byte sequences are not valid UTF-8 (e.g. E0 80 A0 which is an overlong encoding for a space) so you need to take care to avoid these.

It would be helpful if your "Try It Online" or similar link includes a footer that helps demonstrate the correctness of your output, where this is not obvious from the I/O format or code.

This is , so the shortest program or function that breaks no standard loopholes wins!

Lexicographically earliest valid UTF-8 byte sequence permutation

There are currently 1,114,112 possible Unicode characters. Each character has a unique valid byte sequence in the UTF-8 encoding. Different characters have different length encodings:

  • ASCII characters have a 1-byte encoding 00-7F.
  • The next 1920 characters have a 2-byte encoding C2 80-DF BF.
  • The rest of the BMP has a 3-byte encoding E0 A0 80-ED 9F BF and EE 80 80-EF BF BF.
  • The other planes have a 4-byte encoding F0 90 80 80-F4 8F BF BF.

It's possible for two strings of Unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A1 C3 A2) and ¢á (C2 A2 C3 A1).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that finds the string whose UTF-8 byte sequence is lexicographically earliest of all such sequences that are permutations of the UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A2 C3 A1 62 61) your output would be ab¡âᴵ (61 62 C2 A1 C3 A2 E1 B4 B5).

Note however that some byte sequences are not valid UTF-8 (e.g. E0 80 A0 which is an overlong encoding for a space) so you need to take care to avoid these.

It would be helpful if your "Try It Online" or similar link includes a footer that helps demonstrate the correctness of your output, where this is not obvious from the I/O format or code.

This is , so the shortest program or function that breaks no standard loopholes wins!

Lexicographically earliest valid UTF-8 byte sequence permutation

There are currently 1,114,112 possible Unicode characters (code points). Each character has a unique valid byte sequence in the UTF-8 encoding. Different characters have different length encodings:

  • ASCII characters have a 1-byte encoding 00-7F.
  • The next 1920 characters have a 2-byte encoding C2 80-DF BF.
  • The rest of the BMP has a 3-byte encoding E0 A0 80-ED 9F BF and EE 80 80-EF BF BF.
  • The other planes have a 4-byte encoding F0 90 80 80-F4 8F BF BF.

It's possible for two strings (specific non-normalised sequences of Unicode code points) of Unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A1 C3 A2) and ¢á (C2 A2 C3 A1).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that finds the string whose UTF-8 byte sequence is lexicographically earliest of all such sequences that are permutations of the UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A2 C3 A1 62 61) your output would be ab¡âᴵ (61 62 C2 A1 C3 A2 E1 B4 B5).

Note however that some byte sequences are not valid UTF-8 (e.g. E0 80 A0 which is an overlong encoding for a space) so you need to take care to avoid these.

It would be helpful if your "Try It Online" or similar link includes a footer that helps demonstrate the correctness of your output, where this is not obvious from the I/O format or code.

This is , so the shortest program or function that breaks no standard loopholes wins!

added 332 characters in body
Source Link
Neil
  • 177.2k
  • 20
  • 9

Lexicographically earliest canonicalvalid UTF-8 byte sequence permutation

There are currently 1,114,112 possible Unicode characters. Each character has a unique valid byte sequence in the UTF-8 encoding. Different characters have different length encodings:

  • ASCII characters have a 1-byte encoding 00-7F.
  • The next 1920 characters have a 2-byte encoding C2 80-DF BF.
  • The rest of the BMP has a 3-byte encoding E0 A0 80-ED 9F BF and EE 80 80-EF BF BF.
  • The other planes have a 4-byte encoding F0 90 80 80-F4 8F BF BF.

It's possible for two strings of unicodeUnicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A0A1 C3 A1A2) and ¢á (C2 A1A2 C3 A0A1).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that returnsfinds the Unicode string whose canonical UTF-8 byte sequence is the lexicographically earliest of all such sequences that are permutations of the canonical UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A1A2 C3 A0A1 62 61) your output would be ab¡âᴵ (61 62 C2 A0A1 C3 A1A2 E1 B4 B5).

If you provideNote however that some byte sequences are not valid UTF-8 (e.g. E0 80 A0 which is an overlong encoding for a space) so you need to take care to avoid these.

It would be helpful if your "Try It Online" or similar link, and it is not clear from the code that the output is canonical and/or a permutation of the input, please add includes a validation footer. For instance, if your I/O is in that helps demonstrate the formcorrectness of UTF-8 bytes, your footer could convert the result to Unicode and backoutput, while if itwhere this is innot obvious from the form of UnicodeI/O format or code points, your footer could convert the input and output to UTF-8 bytes and show that one is a permutation of the other.

This is , so the shortest program or function that breaks no standard loopholes wins!

Lexicographically earliest canonical UTF-8 byte sequence permutation

It's possible for two strings of unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A0 C3 A1) and ¢á (C2 A1 C3 A0).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that returns the Unicode string whose canonical UTF-8 byte sequence is the lexicographically earliest of all such sequences that are permutations of the canonical UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A1 C3 A0 62 61) your output would be ab¡âᴵ (61 62 C2 A0 C3 A1 E1 B4 B5).

If you provide a "Try It Online" or similar link, and it is not clear from the code that the output is canonical and/or a permutation of the input, please add a validation footer. For instance, if your I/O is in the form of UTF-8 bytes, your footer could convert the result to Unicode and back, while if it is in the form of Unicode code points, your footer could convert the input and output to UTF-8 bytes and show that one is a permutation of the other.

This is , so the shortest program or function that breaks no standard loopholes wins!

Lexicographically earliest valid UTF-8 byte sequence permutation

There are currently 1,114,112 possible Unicode characters. Each character has a unique valid byte sequence in the UTF-8 encoding. Different characters have different length encodings:

  • ASCII characters have a 1-byte encoding 00-7F.
  • The next 1920 characters have a 2-byte encoding C2 80-DF BF.
  • The rest of the BMP has a 3-byte encoding E0 A0 80-ED 9F BF and EE 80 80-EF BF BF.
  • The other planes have a 4-byte encoding F0 90 80 80-F4 8F BF BF.

It's possible for two strings of Unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A1 C3 A2) and ¢á (C2 A2 C3 A1).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that finds the string whose UTF-8 byte sequence is lexicographically earliest of all such sequences that are permutations of the UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A2 C3 A1 62 61) your output would be ab¡âᴵ (61 62 C2 A1 C3 A2 E1 B4 B5).

Note however that some byte sequences are not valid UTF-8 (e.g. E0 80 A0 which is an overlong encoding for a space) so you need to take care to avoid these.

It would be helpful if your "Try It Online" or similar link includes a footer that helps demonstrate the correctness of your output, where this is not obvious from the I/O format or code.

This is , so the shortest program or function that breaks no standard loopholes wins!

added 91 characters in body
Source Link
Neil
  • 177.2k
  • 20
  • 9

Lexicographically earliest canonical UTF-8 byte sequence permutation

It's possible for two strings of unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A0 C3 A1) and ¢á (C2 A1 C3 A0).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that, given a Unicode string, returns the Unicode string whose canonical UTF-8 byte sequence is the lexicographically earliest permutation of itsall such sequences that are permutations of the canonical UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A1 C3 A0 62 61) your output would be ab¡âᴵ (61 62 C2 A0 C3 A1 E1 B4 B5).

If you provide a "Try It Online" or similar link, and it is not clear from the code that the output is canonical and/or a permutation of the input, please add a validation footer. For instance, if your I/O is in the form of UTF-8 bytes, your footer could convert the result to Unicode and back, while if it is in the form of Unicode code points, your footer could convert the input and output to UTF-8 bytes and show that one is a permutation of the other.

This is , so the shortest program or function that breaks no standard loopholes wins!

Lexicographically earliest canonical UTF-8 byte sequence permutation

It's possible for two strings of unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A0 C3 A1) and ¢á (C2 A1 C3 A0).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that, given a Unicode string, returns the Unicode string whose canonical UTF-8 byte sequence is the lexicographically earliest permutation of its canonical UTF-8 byte sequence.

For example, if your input is ᵴ¢ába your output would be ab¡âᴵ.

If you provide a "Try It Online" or similar link, and it is not clear from the code that the output is canonical and/or a permutation of the input, please add a validation footer. For instance, if your I/O is in the form of UTF-8 bytes, your footer could convert the result to Unicode and back, while if it is in the form of Unicode code points, your footer could convert the input and output to UTF-8 bytes and show that one is a permutation of the other.

This is , so the shortest program or function that breaks no standard loopholes wins!

Lexicographically earliest canonical UTF-8 byte sequence permutation

It's possible for two strings of unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A0 C3 A1) and ¢á (C2 A1 C3 A0).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that returns the Unicode string whose canonical UTF-8 byte sequence is the lexicographically earliest of all such sequences that are permutations of the canonical UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A1 C3 A0 62 61) your output would be ab¡âᴵ (61 62 C2 A0 C3 A1 E1 B4 B5).

If you provide a "Try It Online" or similar link, and it is not clear from the code that the output is canonical and/or a permutation of the input, please add a validation footer. For instance, if your I/O is in the form of UTF-8 bytes, your footer could convert the result to Unicode and back, while if it is in the form of Unicode code points, your footer could convert the input and output to UTF-8 bytes and show that one is a permutation of the other.

This is , so the shortest program or function that breaks no standard loopholes wins!

Source Link
Neil
  • 177.2k
  • 20
  • 9
Loading