Increment a GUID
Python 2, 50
- 3 bytes saved thanks to @Dennis.
lambda s:UUID(int=UUID(s).int+1)
from uuid import*
Try it online!
JavaScript (ES6), 85 bytes
The output string is in lowercase.
s=>(g=(c,x=+('0x'+s[--n])+!!c)=>1/x?g(x>>4)+(x&15).toString(16):~n?g(c)+'-':'')(n=36)
Try it online!
Commented
s => ( // s = GUID
g = ( // g = recursive function taking:
c, // c = carry from the previous iteration
x = +('0x' + s[--n]) // x = decimal conversion of the current digit
+ !!c // add the carry
) => //
1 / x ? // if x is numeric:
g(x >> 4) + // do a recursive call, using the new carry
(x & 15) // and append the next digit
.toString(16) // converted back to hexadecimal
: // else:
~n ? // if n is not equal to -1:
g(c) // do a recursive call, leaving the current carry unchanged
+ '-' // and append a hyphen
: // else:
'' // stop recursion
)(n = 36) // initial call to g with n = 36 and a truthy carry
05AB1E, 17 15 18 bytes
Saved 2 bytes thanks to Kevin Cruijssen
'-K1ìH>h¦Ž¦˜S·£'-ý
Try it online! or as a Test Suite
Explanation
'-K # remove "-" from input
1ì # prepend a 1 (to preserve leading 0s)
H # convert from hex to base 10
> # increment
h # convert to hex from base 10
¦ # remove the extra 1
Ž¦˜S· # push [8, 4, 4, 4, 12]
£ # split into parts of these sizes
'-ý # join on "-"