Inspired by a recent Daily WTF article...
Write a program or function that takes a GUID (string in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, where each X represents a hexadecimal digit), and outputs the GUID incremented by one.
Examples
>>> increment_guid('7f128bd4-b0ba-4597-8f35-3a2f2756dfbb') '7f128bd4-b0ba-4597-8f35-3a2f2756dfbc' >>> increment_guid('06b86883-f3e7-4f9d-87c5-a047e89a19fa') '06b86883-f3e7-4f9d-87c5-a047e89a19fb' >>> increment_guid('89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2cf') '89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2d0' >>> increment_guid('89f25f2f-2f7b-4aa6-b9d7-46a98e3cb29f') '89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2a0' >>> increment_guid('8e0f9835-4086-406b-b7a4-532da46963ff') '8e0f9835-4086-406b-b7a4-532da4696400' >>> increment_guid('7f128bd4-b0ba-4597-ffff-ffffffffffff') '7f128bd4-b0ba-4598-0000-000000000000' Notes
- Unlike in the linked article, incrementing a GUID that ends in F must “carry” to the previous hex digit. See examples above.
- You may assume that the input will not be
ffffffff-ffff-ffff-ffff-ffffffffffff. - For hex digits above 9, you may use either upper (A-F) or lower (a-f) case.
- Yes, GUIDs may start with a
0. - Your output must consist of exactly 32 hex digits and 4 hyphens in the expected format, including any necessary leading
0s. - You do not have to preserve the version number or other fixed bits of the GUID. Assume it's just a 128-bit integer where none of the bits have any special meaning. Similarly, GUIDs are assumed to sort in straightforward lexicographical order rather than in the binary order of a Windows
GUIDstruct. - If writing a function, the input may be of any sequence-of-
chardata type:string,char[],List<char>, etc.
GUIDstruct. \$\endgroup\$89f25f2f-2f7b-4aa6-b9d7-46a98e3cb29fto ensure that answers can make the transition9 -> a. \$\endgroup\$foreach (char ch in theInput)is valid. \$\endgroup\$