Increment a GUID












5












$begingroup$


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('89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2cf')
'89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2d0'
>>> increment_guid('8e0f9835-4086-406b-b7a4-532da46963ff')
'8e0f9835-4086-406b-b7a4-532da4696400'


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 must accept both uppercase A-F and lowercase a-f on input. Output may be in either case.










share|improve this question









$endgroup$








  • 2




    $begingroup$
    Suggested test case: 7f128bd4-b0ba-4597-ffff-ffffffffffff (carry 'across' dash)
    $endgroup$
    – Sanchises
    1 hour ago










  • $begingroup$
    Are we supposed to leave the 6 fixed bits in the UUIDv4 intact?
    $endgroup$
    – Filip Haglund
    27 mins ago
















5












$begingroup$


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('89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2cf')
'89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2d0'
>>> increment_guid('8e0f9835-4086-406b-b7a4-532da46963ff')
'8e0f9835-4086-406b-b7a4-532da4696400'


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 must accept both uppercase A-F and lowercase a-f on input. Output may be in either case.










share|improve this question









$endgroup$








  • 2




    $begingroup$
    Suggested test case: 7f128bd4-b0ba-4597-ffff-ffffffffffff (carry 'across' dash)
    $endgroup$
    – Sanchises
    1 hour ago










  • $begingroup$
    Are we supposed to leave the 6 fixed bits in the UUIDv4 intact?
    $endgroup$
    – Filip Haglund
    27 mins ago














5












5








5


1



$begingroup$


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('89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2cf')
'89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2d0'
>>> increment_guid('8e0f9835-4086-406b-b7a4-532da46963ff')
'8e0f9835-4086-406b-b7a4-532da4696400'


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 must accept both uppercase A-F and lowercase a-f on input. Output may be in either case.










share|improve this question









$endgroup$




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('89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2cf')
'89f25f2f-2f7b-4aa6-b9d7-46a98e3cb2d0'
>>> increment_guid('8e0f9835-4086-406b-b7a4-532da46963ff')
'8e0f9835-4086-406b-b7a4-532da4696400'


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 must accept both uppercase A-F and lowercase a-f on input. Output may be in either case.







code-golf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 7 hours ago









dan04dan04

4,01821933




4,01821933








  • 2




    $begingroup$
    Suggested test case: 7f128bd4-b0ba-4597-ffff-ffffffffffff (carry 'across' dash)
    $endgroup$
    – Sanchises
    1 hour ago










  • $begingroup$
    Are we supposed to leave the 6 fixed bits in the UUIDv4 intact?
    $endgroup$
    – Filip Haglund
    27 mins ago














  • 2




    $begingroup$
    Suggested test case: 7f128bd4-b0ba-4597-ffff-ffffffffffff (carry 'across' dash)
    $endgroup$
    – Sanchises
    1 hour ago










  • $begingroup$
    Are we supposed to leave the 6 fixed bits in the UUIDv4 intact?
    $endgroup$
    – Filip Haglund
    27 mins ago








2




2




$begingroup$
Suggested test case: 7f128bd4-b0ba-4597-ffff-ffffffffffff (carry 'across' dash)
$endgroup$
– Sanchises
1 hour ago




$begingroup$
Suggested test case: 7f128bd4-b0ba-4597-ffff-ffffffffffff (carry 'across' dash)
$endgroup$
– Sanchises
1 hour ago












$begingroup$
Are we supposed to leave the 6 fixed bits in the UUIDv4 intact?
$endgroup$
– Filip Haglund
27 mins ago




$begingroup$
Are we supposed to leave the 6 fixed bits in the UUIDv4 intact?
$endgroup$
– Filip Haglund
27 mins ago










10 Answers
10






active

oldest

votes


















2












$begingroup$

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





share|improve this answer











$endgroup$





















    1












    $begingroup$


    APL (Dyalog Unicode), 46 bytesSBCS





    Anonymous tacit prefix function.



    ⎕CY'dfns'
    (∊1hex 16(|+1⌽=)⍣≡1+@32dec¨)@('-'≠⊢)


    Try it online!



    ⎕CY'dfns'copy the "dfns" library (to get hex and dec)



    ()

     the argument

     differs from

    '-' a dash
    ()@ on the subset consisting of the locations at which the above criterion is true, apply:

    dec¨ convert each hexadecimal character to a decimal number

     …@32at position 32 (the last digit), apply:

      1+ increment

    16()⍣≡ repeatedly apply with left argument 16 until stable:

      = compare (gives mask where the hexadecimal digits are 16)

      1⌽ cyclically rotate one step left (this is the carry bit)

      |+ to that, add the division remainder when divided (by sixteen, thus making all 16 into 0)

    1hex  turn digits into length-one hexadecimal character representations

    ϵnlist (flatten)






    share|improve this answer











    $endgroup$





















      1












      $begingroup$


      05AB1E, 17 15 bytes



      Saved 2 bytes thanks to Kevin Cruijssen



      '-KH>hŽ¦˜S·£'-ý


      Try it online!
      or as a Test Suite



      Explanation



      '-K               # remove "-" from input
      H # convert from hex to base 10
      > # increment
      h # convert to hex from base 10
      Ž¦˜S· # push [8, 4, 4, 4, 12]
      £ # split into parts of these sizes
      '-ý # join on "-"





      share|improve this answer











      $endgroup$













      • $begingroup$
        Dang, you beat me to it.. Had something very similar, but with žKà instead of '-K. Btw, you can save 2 bytes by changing •É]•S3+ to Ž¦˜S·.
        $endgroup$
        – Kevin Cruijssen
        36 mins ago










      • $begingroup$
        @KevinCruijssen: Thanks! I don't know how many times I've kept forgetting that Ž is a thing now...
        $endgroup$
        – Emigna
        33 mins ago



















      0












      $begingroup$


      Perl 6, 65 bytes





      {(:16(TR/-//)+1).base(16).comb.rotor(8,4,4,4,*)».join.join('-')}


      Test it






      share|improve this answer









      $endgroup$













      • $begingroup$
        56 bytes
        $endgroup$
        – Jo King
        5 hours ago










      • $begingroup$
        52 bytes
        $endgroup$
        – nwellnhof
        1 hour ago



















      0












      $begingroup$


      Python 2, 53





      from uuid import*
      print UUID(int=UUID(input()).int+1)


      Try it online!






      share|improve this answer









      $endgroup$





















        0












        $begingroup$


        Python 2, 113 112 bytes





        def f(s):a=hex(int(s.replace('-',''),16)+1+2**128);return'-'.join((a[3:11],a[11:15],a[15:19],a[19:23],a[23:-1]))


        Try it online!



        Without imports






        share|improve this answer











        $endgroup$





















          0












          $begingroup$


          Retina 0.8.2, 21 bytes



          T`FfdlL`0dlL`.[-Ff]*$


          Try it online! Link includes test cases. 9 becomes a. Explanation: The regex matches all trailing fs and -s plus one preceding character. The transliteration then cyclically increments those characters as if they were hex digits. Alternate approach, also 21 bytes:



          T`L`l
          T`fo`dl`.[-f]*$


          Try it online! Link includes test cases. Works by lowercasing the input to simplify the transliteration. Would therefore be 15 bytes if it only had to support lowercase. Try it online! Link includes test cases.






          share|improve this answer









          $endgroup$





















            0












            $begingroup$

            MATLAB, 138 bytes





            a=1;Z=a;for q=flip(split(input(''),'-'))'
            z=dec2hex(hex2dec(q)+a);if nnz(z)>nnz(q{:})
            z=~q{:}+48;else
            a=0;end
            Z=[z 45 Z];end;disp(Z(1:36))


            Explanation



            The hex2dec function spits out a double, so it cannot process the entire GUID at once to avoid exceeding flintmax. Instead, we have to process the GUID chunk by chunck, using split. The variable a checks if we need to carry a one, and cheatingly also is the initial increment we add. The condition for carrying over is whether the lengths of the original and incremented strings are no longer equal.



            Original version was just under 160 bytes so I'd like to think this should not be easy to outgolf.






            share|improve this answer









            $endgroup$





















              0












              $begingroup$


              Ruby -pl, 62 57 bytes





              $_=(1+gsub(?-,"").hex).to_s 16
              7.step(22,5){|i|$_[i]+=?-}


              Try it online!






              share|improve this answer









              $endgroup$





















                0












                $begingroup$

                Java 11, 152 149 bytes





                s->{var t=new java.math.BigInteger(s.replace("-",""),16);return(t.add(t.ONE).toString(16)).replaceAll("(.{4})".repeat(5)+"(.*)","$1$2-$3-$4-$5-$6");}


                Try it online.



                Explanation:



                s->{                              // Method with String as both parameter and return-type
                var t=new java.math.BigInteger( // Create a BigInteger
                s.replace("-",""), // Of the input-string with all "-" removed
                16); // Converted from Hexadecimal
                return(t.add(t.ONE) // Add 1
                .toString(16)) // And convert it back to a Hexadecimal String
                .replaceAll("(.{4})".repeat(5)+"(.*)",
                // And split the string into parts of sizes 4,4,4,4,4,rest
                "$1$2-$3-$4-$5-$6");} // And insert "-" after parts of size 8,4,4,4,
                // and return it as result




                share











                $endgroup$













                  Your Answer





                  StackExchange.ifUsing("editor", function () {
                  return StackExchange.using("mathjaxEditing", function () {
                  StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                  StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                  });
                  });
                  }, "mathjax-editing");

                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "200"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178837%2fincrement-a-guid%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  10 Answers
                  10






                  active

                  oldest

                  votes








                  10 Answers
                  10






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  2












                  $begingroup$

                  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





                  share|improve this answer











                  $endgroup$


















                    2












                    $begingroup$

                    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





                    share|improve this answer











                    $endgroup$
















                      2












                      2








                      2





                      $begingroup$

                      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





                      share|improve this answer











                      $endgroup$



                      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






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 59 mins ago

























                      answered 1 hour ago









                      ArnauldArnauld

                      73.4k689308




                      73.4k689308























                          1












                          $begingroup$


                          APL (Dyalog Unicode), 46 bytesSBCS





                          Anonymous tacit prefix function.



                          ⎕CY'dfns'
                          (∊1hex 16(|+1⌽=)⍣≡1+@32dec¨)@('-'≠⊢)


                          Try it online!



                          ⎕CY'dfns'copy the "dfns" library (to get hex and dec)



                          ()

                           the argument

                           differs from

                          '-' a dash
                          ()@ on the subset consisting of the locations at which the above criterion is true, apply:

                          dec¨ convert each hexadecimal character to a decimal number

                           …@32at position 32 (the last digit), apply:

                            1+ increment

                          16()⍣≡ repeatedly apply with left argument 16 until stable:

                            = compare (gives mask where the hexadecimal digits are 16)

                            1⌽ cyclically rotate one step left (this is the carry bit)

                            |+ to that, add the division remainder when divided (by sixteen, thus making all 16 into 0)

                          1hex  turn digits into length-one hexadecimal character representations

                          ϵnlist (flatten)






                          share|improve this answer











                          $endgroup$


















                            1












                            $begingroup$


                            APL (Dyalog Unicode), 46 bytesSBCS





                            Anonymous tacit prefix function.



                            ⎕CY'dfns'
                            (∊1hex 16(|+1⌽=)⍣≡1+@32dec¨)@('-'≠⊢)


                            Try it online!



                            ⎕CY'dfns'copy the "dfns" library (to get hex and dec)



                            ()

                             the argument

                             differs from

                            '-' a dash
                            ()@ on the subset consisting of the locations at which the above criterion is true, apply:

                            dec¨ convert each hexadecimal character to a decimal number

                             …@32at position 32 (the last digit), apply:

                              1+ increment

                            16()⍣≡ repeatedly apply with left argument 16 until stable:

                              = compare (gives mask where the hexadecimal digits are 16)

                              1⌽ cyclically rotate one step left (this is the carry bit)

                              |+ to that, add the division remainder when divided (by sixteen, thus making all 16 into 0)

                            1hex  turn digits into length-one hexadecimal character representations

                            ϵnlist (flatten)






                            share|improve this answer











                            $endgroup$
















                              1












                              1








                              1





                              $begingroup$


                              APL (Dyalog Unicode), 46 bytesSBCS





                              Anonymous tacit prefix function.



                              ⎕CY'dfns'
                              (∊1hex 16(|+1⌽=)⍣≡1+@32dec¨)@('-'≠⊢)


                              Try it online!



                              ⎕CY'dfns'copy the "dfns" library (to get hex and dec)



                              ()

                               the argument

                               differs from

                              '-' a dash
                              ()@ on the subset consisting of the locations at which the above criterion is true, apply:

                              dec¨ convert each hexadecimal character to a decimal number

                               …@32at position 32 (the last digit), apply:

                                1+ increment

                              16()⍣≡ repeatedly apply with left argument 16 until stable:

                                = compare (gives mask where the hexadecimal digits are 16)

                                1⌽ cyclically rotate one step left (this is the carry bit)

                                |+ to that, add the division remainder when divided (by sixteen, thus making all 16 into 0)

                              1hex  turn digits into length-one hexadecimal character representations

                              ϵnlist (flatten)






                              share|improve this answer











                              $endgroup$




                              APL (Dyalog Unicode), 46 bytesSBCS





                              Anonymous tacit prefix function.



                              ⎕CY'dfns'
                              (∊1hex 16(|+1⌽=)⍣≡1+@32dec¨)@('-'≠⊢)


                              Try it online!



                              ⎕CY'dfns'copy the "dfns" library (to get hex and dec)



                              ()

                               the argument

                               differs from

                              '-' a dash
                              ()@ on the subset consisting of the locations at which the above criterion is true, apply:

                              dec¨ convert each hexadecimal character to a decimal number

                               …@32at position 32 (the last digit), apply:

                                1+ increment

                              16()⍣≡ repeatedly apply with left argument 16 until stable:

                                = compare (gives mask where the hexadecimal digits are 16)

                                1⌽ cyclically rotate one step left (this is the carry bit)

                                |+ to that, add the division remainder when divided (by sixteen, thus making all 16 into 0)

                              1hex  turn digits into length-one hexadecimal character representations

                              ϵnlist (flatten)







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 1 hour ago

























                              answered 1 hour ago









                              AdámAdám

                              29.3k270194




                              29.3k270194























                                  1












                                  $begingroup$


                                  05AB1E, 17 15 bytes



                                  Saved 2 bytes thanks to Kevin Cruijssen



                                  '-KH>hŽ¦˜S·£'-ý


                                  Try it online!
                                  or as a Test Suite



                                  Explanation



                                  '-K               # remove "-" from input
                                  H # convert from hex to base 10
                                  > # increment
                                  h # convert to hex from base 10
                                  Ž¦˜S· # push [8, 4, 4, 4, 12]
                                  £ # split into parts of these sizes
                                  '-ý # join on "-"





                                  share|improve this answer











                                  $endgroup$













                                  • $begingroup$
                                    Dang, you beat me to it.. Had something very similar, but with žKà instead of '-K. Btw, you can save 2 bytes by changing •É]•S3+ to Ž¦˜S·.
                                    $endgroup$
                                    – Kevin Cruijssen
                                    36 mins ago










                                  • $begingroup$
                                    @KevinCruijssen: Thanks! I don't know how many times I've kept forgetting that Ž is a thing now...
                                    $endgroup$
                                    – Emigna
                                    33 mins ago
















                                  1












                                  $begingroup$


                                  05AB1E, 17 15 bytes



                                  Saved 2 bytes thanks to Kevin Cruijssen



                                  '-KH>hŽ¦˜S·£'-ý


                                  Try it online!
                                  or as a Test Suite



                                  Explanation



                                  '-K               # remove "-" from input
                                  H # convert from hex to base 10
                                  > # increment
                                  h # convert to hex from base 10
                                  Ž¦˜S· # push [8, 4, 4, 4, 12]
                                  £ # split into parts of these sizes
                                  '-ý # join on "-"





                                  share|improve this answer











                                  $endgroup$













                                  • $begingroup$
                                    Dang, you beat me to it.. Had something very similar, but with žKà instead of '-K. Btw, you can save 2 bytes by changing •É]•S3+ to Ž¦˜S·.
                                    $endgroup$
                                    – Kevin Cruijssen
                                    36 mins ago










                                  • $begingroup$
                                    @KevinCruijssen: Thanks! I don't know how many times I've kept forgetting that Ž is a thing now...
                                    $endgroup$
                                    – Emigna
                                    33 mins ago














                                  1












                                  1








                                  1





                                  $begingroup$


                                  05AB1E, 17 15 bytes



                                  Saved 2 bytes thanks to Kevin Cruijssen



                                  '-KH>hŽ¦˜S·£'-ý


                                  Try it online!
                                  or as a Test Suite



                                  Explanation



                                  '-K               # remove "-" from input
                                  H # convert from hex to base 10
                                  > # increment
                                  h # convert to hex from base 10
                                  Ž¦˜S· # push [8, 4, 4, 4, 12]
                                  £ # split into parts of these sizes
                                  '-ý # join on "-"





                                  share|improve this answer











                                  $endgroup$




                                  05AB1E, 17 15 bytes



                                  Saved 2 bytes thanks to Kevin Cruijssen



                                  '-KH>hŽ¦˜S·£'-ý


                                  Try it online!
                                  or as a Test Suite



                                  Explanation



                                  '-K               # remove "-" from input
                                  H # convert from hex to base 10
                                  > # increment
                                  h # convert to hex from base 10
                                  Ž¦˜S· # push [8, 4, 4, 4, 12]
                                  £ # split into parts of these sizes
                                  '-ý # join on "-"






                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited 30 mins ago

























                                  answered 1 hour ago









                                  EmignaEmigna

                                  45.6k432139




                                  45.6k432139












                                  • $begingroup$
                                    Dang, you beat me to it.. Had something very similar, but with žKà instead of '-K. Btw, you can save 2 bytes by changing •É]•S3+ to Ž¦˜S·.
                                    $endgroup$
                                    – Kevin Cruijssen
                                    36 mins ago










                                  • $begingroup$
                                    @KevinCruijssen: Thanks! I don't know how many times I've kept forgetting that Ž is a thing now...
                                    $endgroup$
                                    – Emigna
                                    33 mins ago


















                                  • $begingroup$
                                    Dang, you beat me to it.. Had something very similar, but with žKà instead of '-K. Btw, you can save 2 bytes by changing •É]•S3+ to Ž¦˜S·.
                                    $endgroup$
                                    – Kevin Cruijssen
                                    36 mins ago










                                  • $begingroup$
                                    @KevinCruijssen: Thanks! I don't know how many times I've kept forgetting that Ž is a thing now...
                                    $endgroup$
                                    – Emigna
                                    33 mins ago
















                                  $begingroup$
                                  Dang, you beat me to it.. Had something very similar, but with žKà instead of '-K. Btw, you can save 2 bytes by changing •É]•S3+ to Ž¦˜S·.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  36 mins ago




                                  $begingroup$
                                  Dang, you beat me to it.. Had something very similar, but with žKà instead of '-K. Btw, you can save 2 bytes by changing •É]•S3+ to Ž¦˜S·.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  36 mins ago












                                  $begingroup$
                                  @KevinCruijssen: Thanks! I don't know how many times I've kept forgetting that Ž is a thing now...
                                  $endgroup$
                                  – Emigna
                                  33 mins ago




                                  $begingroup$
                                  @KevinCruijssen: Thanks! I don't know how many times I've kept forgetting that Ž is a thing now...
                                  $endgroup$
                                  – Emigna
                                  33 mins ago











                                  0












                                  $begingroup$


                                  Perl 6, 65 bytes





                                  {(:16(TR/-//)+1).base(16).comb.rotor(8,4,4,4,*)».join.join('-')}


                                  Test it






                                  share|improve this answer









                                  $endgroup$













                                  • $begingroup$
                                    56 bytes
                                    $endgroup$
                                    – Jo King
                                    5 hours ago










                                  • $begingroup$
                                    52 bytes
                                    $endgroup$
                                    – nwellnhof
                                    1 hour ago
















                                  0












                                  $begingroup$


                                  Perl 6, 65 bytes





                                  {(:16(TR/-//)+1).base(16).comb.rotor(8,4,4,4,*)».join.join('-')}


                                  Test it






                                  share|improve this answer









                                  $endgroup$













                                  • $begingroup$
                                    56 bytes
                                    $endgroup$
                                    – Jo King
                                    5 hours ago










                                  • $begingroup$
                                    52 bytes
                                    $endgroup$
                                    – nwellnhof
                                    1 hour ago














                                  0












                                  0








                                  0





                                  $begingroup$


                                  Perl 6, 65 bytes





                                  {(:16(TR/-//)+1).base(16).comb.rotor(8,4,4,4,*)».join.join('-')}


                                  Test it






                                  share|improve this answer









                                  $endgroup$




                                  Perl 6, 65 bytes





                                  {(:16(TR/-//)+1).base(16).comb.rotor(8,4,4,4,*)».join.join('-')}


                                  Test it







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered 6 hours ago









                                  Brad Gilbert b2gillsBrad Gilbert b2gills

                                  12.2k11232




                                  12.2k11232












                                  • $begingroup$
                                    56 bytes
                                    $endgroup$
                                    – Jo King
                                    5 hours ago










                                  • $begingroup$
                                    52 bytes
                                    $endgroup$
                                    – nwellnhof
                                    1 hour ago


















                                  • $begingroup$
                                    56 bytes
                                    $endgroup$
                                    – Jo King
                                    5 hours ago










                                  • $begingroup$
                                    52 bytes
                                    $endgroup$
                                    – nwellnhof
                                    1 hour ago
















                                  $begingroup$
                                  56 bytes
                                  $endgroup$
                                  – Jo King
                                  5 hours ago




                                  $begingroup$
                                  56 bytes
                                  $endgroup$
                                  – Jo King
                                  5 hours ago












                                  $begingroup$
                                  52 bytes
                                  $endgroup$
                                  – nwellnhof
                                  1 hour ago




                                  $begingroup$
                                  52 bytes
                                  $endgroup$
                                  – nwellnhof
                                  1 hour ago











                                  0












                                  $begingroup$


                                  Python 2, 53





                                  from uuid import*
                                  print UUID(int=UUID(input()).int+1)


                                  Try it online!






                                  share|improve this answer









                                  $endgroup$


















                                    0












                                    $begingroup$


                                    Python 2, 53





                                    from uuid import*
                                    print UUID(int=UUID(input()).int+1)


                                    Try it online!






                                    share|improve this answer









                                    $endgroup$
















                                      0












                                      0








                                      0





                                      $begingroup$


                                      Python 2, 53





                                      from uuid import*
                                      print UUID(int=UUID(input()).int+1)


                                      Try it online!






                                      share|improve this answer









                                      $endgroup$




                                      Python 2, 53





                                      from uuid import*
                                      print UUID(int=UUID(input()).int+1)


                                      Try it online!







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 5 hours ago









                                      Digital TraumaDigital Trauma

                                      58.6k787221




                                      58.6k787221























                                          0












                                          $begingroup$


                                          Python 2, 113 112 bytes





                                          def f(s):a=hex(int(s.replace('-',''),16)+1+2**128);return'-'.join((a[3:11],a[11:15],a[15:19],a[19:23],a[23:-1]))


                                          Try it online!



                                          Without imports






                                          share|improve this answer











                                          $endgroup$


















                                            0












                                            $begingroup$


                                            Python 2, 113 112 bytes





                                            def f(s):a=hex(int(s.replace('-',''),16)+1+2**128);return'-'.join((a[3:11],a[11:15],a[15:19],a[19:23],a[23:-1]))


                                            Try it online!



                                            Without imports






                                            share|improve this answer











                                            $endgroup$
















                                              0












                                              0








                                              0





                                              $begingroup$


                                              Python 2, 113 112 bytes





                                              def f(s):a=hex(int(s.replace('-',''),16)+1+2**128);return'-'.join((a[3:11],a[11:15],a[15:19],a[19:23],a[23:-1]))


                                              Try it online!



                                              Without imports






                                              share|improve this answer











                                              $endgroup$




                                              Python 2, 113 112 bytes





                                              def f(s):a=hex(int(s.replace('-',''),16)+1+2**128);return'-'.join((a[3:11],a[11:15],a[15:19],a[19:23],a[23:-1]))


                                              Try it online!



                                              Without imports







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited 1 hour ago

























                                              answered 2 hours ago









                                              TFeldTFeld

                                              14.5k21240




                                              14.5k21240























                                                  0












                                                  $begingroup$


                                                  Retina 0.8.2, 21 bytes



                                                  T`FfdlL`0dlL`.[-Ff]*$


                                                  Try it online! Link includes test cases. 9 becomes a. Explanation: The regex matches all trailing fs and -s plus one preceding character. The transliteration then cyclically increments those characters as if they were hex digits. Alternate approach, also 21 bytes:



                                                  T`L`l
                                                  T`fo`dl`.[-f]*$


                                                  Try it online! Link includes test cases. Works by lowercasing the input to simplify the transliteration. Would therefore be 15 bytes if it only had to support lowercase. Try it online! Link includes test cases.






                                                  share|improve this answer









                                                  $endgroup$


















                                                    0












                                                    $begingroup$


                                                    Retina 0.8.2, 21 bytes



                                                    T`FfdlL`0dlL`.[-Ff]*$


                                                    Try it online! Link includes test cases. 9 becomes a. Explanation: The regex matches all trailing fs and -s plus one preceding character. The transliteration then cyclically increments those characters as if they were hex digits. Alternate approach, also 21 bytes:



                                                    T`L`l
                                                    T`fo`dl`.[-f]*$


                                                    Try it online! Link includes test cases. Works by lowercasing the input to simplify the transliteration. Would therefore be 15 bytes if it only had to support lowercase. Try it online! Link includes test cases.






                                                    share|improve this answer









                                                    $endgroup$
















                                                      0












                                                      0








                                                      0





                                                      $begingroup$


                                                      Retina 0.8.2, 21 bytes



                                                      T`FfdlL`0dlL`.[-Ff]*$


                                                      Try it online! Link includes test cases. 9 becomes a. Explanation: The regex matches all trailing fs and -s plus one preceding character. The transliteration then cyclically increments those characters as if they were hex digits. Alternate approach, also 21 bytes:



                                                      T`L`l
                                                      T`fo`dl`.[-f]*$


                                                      Try it online! Link includes test cases. Works by lowercasing the input to simplify the transliteration. Would therefore be 15 bytes if it only had to support lowercase. Try it online! Link includes test cases.






                                                      share|improve this answer









                                                      $endgroup$




                                                      Retina 0.8.2, 21 bytes



                                                      T`FfdlL`0dlL`.[-Ff]*$


                                                      Try it online! Link includes test cases. 9 becomes a. Explanation: The regex matches all trailing fs and -s plus one preceding character. The transliteration then cyclically increments those characters as if they were hex digits. Alternate approach, also 21 bytes:



                                                      T`L`l
                                                      T`fo`dl`.[-f]*$


                                                      Try it online! Link includes test cases. Works by lowercasing the input to simplify the transliteration. Would therefore be 15 bytes if it only had to support lowercase. Try it online! Link includes test cases.







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered 50 mins ago









                                                      NeilNeil

                                                      79.8k744177




                                                      79.8k744177























                                                          0












                                                          $begingroup$

                                                          MATLAB, 138 bytes





                                                          a=1;Z=a;for q=flip(split(input(''),'-'))'
                                                          z=dec2hex(hex2dec(q)+a);if nnz(z)>nnz(q{:})
                                                          z=~q{:}+48;else
                                                          a=0;end
                                                          Z=[z 45 Z];end;disp(Z(1:36))


                                                          Explanation



                                                          The hex2dec function spits out a double, so it cannot process the entire GUID at once to avoid exceeding flintmax. Instead, we have to process the GUID chunk by chunck, using split. The variable a checks if we need to carry a one, and cheatingly also is the initial increment we add. The condition for carrying over is whether the lengths of the original and incremented strings are no longer equal.



                                                          Original version was just under 160 bytes so I'd like to think this should not be easy to outgolf.






                                                          share|improve this answer









                                                          $endgroup$


















                                                            0












                                                            $begingroup$

                                                            MATLAB, 138 bytes





                                                            a=1;Z=a;for q=flip(split(input(''),'-'))'
                                                            z=dec2hex(hex2dec(q)+a);if nnz(z)>nnz(q{:})
                                                            z=~q{:}+48;else
                                                            a=0;end
                                                            Z=[z 45 Z];end;disp(Z(1:36))


                                                            Explanation



                                                            The hex2dec function spits out a double, so it cannot process the entire GUID at once to avoid exceeding flintmax. Instead, we have to process the GUID chunk by chunck, using split. The variable a checks if we need to carry a one, and cheatingly also is the initial increment we add. The condition for carrying over is whether the lengths of the original and incremented strings are no longer equal.



                                                            Original version was just under 160 bytes so I'd like to think this should not be easy to outgolf.






                                                            share|improve this answer









                                                            $endgroup$
















                                                              0












                                                              0








                                                              0





                                                              $begingroup$

                                                              MATLAB, 138 bytes





                                                              a=1;Z=a;for q=flip(split(input(''),'-'))'
                                                              z=dec2hex(hex2dec(q)+a);if nnz(z)>nnz(q{:})
                                                              z=~q{:}+48;else
                                                              a=0;end
                                                              Z=[z 45 Z];end;disp(Z(1:36))


                                                              Explanation



                                                              The hex2dec function spits out a double, so it cannot process the entire GUID at once to avoid exceeding flintmax. Instead, we have to process the GUID chunk by chunck, using split. The variable a checks if we need to carry a one, and cheatingly also is the initial increment we add. The condition for carrying over is whether the lengths of the original and incremented strings are no longer equal.



                                                              Original version was just under 160 bytes so I'd like to think this should not be easy to outgolf.






                                                              share|improve this answer









                                                              $endgroup$



                                                              MATLAB, 138 bytes





                                                              a=1;Z=a;for q=flip(split(input(''),'-'))'
                                                              z=dec2hex(hex2dec(q)+a);if nnz(z)>nnz(q{:})
                                                              z=~q{:}+48;else
                                                              a=0;end
                                                              Z=[z 45 Z];end;disp(Z(1:36))


                                                              Explanation



                                                              The hex2dec function spits out a double, so it cannot process the entire GUID at once to avoid exceeding flintmax. Instead, we have to process the GUID chunk by chunck, using split. The variable a checks if we need to carry a one, and cheatingly also is the initial increment we add. The condition for carrying over is whether the lengths of the original and incremented strings are no longer equal.



                                                              Original version was just under 160 bytes so I'd like to think this should not be easy to outgolf.







                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered 31 mins ago









                                                              SanchisesSanchises

                                                              5,76212351




                                                              5,76212351























                                                                  0












                                                                  $begingroup$


                                                                  Ruby -pl, 62 57 bytes





                                                                  $_=(1+gsub(?-,"").hex).to_s 16
                                                                  7.step(22,5){|i|$_[i]+=?-}


                                                                  Try it online!






                                                                  share|improve this answer









                                                                  $endgroup$


















                                                                    0












                                                                    $begingroup$


                                                                    Ruby -pl, 62 57 bytes





                                                                    $_=(1+gsub(?-,"").hex).to_s 16
                                                                    7.step(22,5){|i|$_[i]+=?-}


                                                                    Try it online!






                                                                    share|improve this answer









                                                                    $endgroup$
















                                                                      0












                                                                      0








                                                                      0





                                                                      $begingroup$


                                                                      Ruby -pl, 62 57 bytes





                                                                      $_=(1+gsub(?-,"").hex).to_s 16
                                                                      7.step(22,5){|i|$_[i]+=?-}


                                                                      Try it online!






                                                                      share|improve this answer









                                                                      $endgroup$




                                                                      Ruby -pl, 62 57 bytes





                                                                      $_=(1+gsub(?-,"").hex).to_s 16
                                                                      7.step(22,5){|i|$_[i]+=?-}


                                                                      Try it online!







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered 15 mins ago









                                                                      Kirill L.Kirill L.

                                                                      3,7251319




                                                                      3,7251319























                                                                          0












                                                                          $begingroup$

                                                                          Java 11, 152 149 bytes





                                                                          s->{var t=new java.math.BigInteger(s.replace("-",""),16);return(t.add(t.ONE).toString(16)).replaceAll("(.{4})".repeat(5)+"(.*)","$1$2-$3-$4-$5-$6");}


                                                                          Try it online.



                                                                          Explanation:



                                                                          s->{                              // Method with String as both parameter and return-type
                                                                          var t=new java.math.BigInteger( // Create a BigInteger
                                                                          s.replace("-",""), // Of the input-string with all "-" removed
                                                                          16); // Converted from Hexadecimal
                                                                          return(t.add(t.ONE) // Add 1
                                                                          .toString(16)) // And convert it back to a Hexadecimal String
                                                                          .replaceAll("(.{4})".repeat(5)+"(.*)",
                                                                          // And split the string into parts of sizes 4,4,4,4,4,rest
                                                                          "$1$2-$3-$4-$5-$6");} // And insert "-" after parts of size 8,4,4,4,
                                                                          // and return it as result




                                                                          share











                                                                          $endgroup$


















                                                                            0












                                                                            $begingroup$

                                                                            Java 11, 152 149 bytes





                                                                            s->{var t=new java.math.BigInteger(s.replace("-",""),16);return(t.add(t.ONE).toString(16)).replaceAll("(.{4})".repeat(5)+"(.*)","$1$2-$3-$4-$5-$6");}


                                                                            Try it online.



                                                                            Explanation:



                                                                            s->{                              // Method with String as both parameter and return-type
                                                                            var t=new java.math.BigInteger( // Create a BigInteger
                                                                            s.replace("-",""), // Of the input-string with all "-" removed
                                                                            16); // Converted from Hexadecimal
                                                                            return(t.add(t.ONE) // Add 1
                                                                            .toString(16)) // And convert it back to a Hexadecimal String
                                                                            .replaceAll("(.{4})".repeat(5)+"(.*)",
                                                                            // And split the string into parts of sizes 4,4,4,4,4,rest
                                                                            "$1$2-$3-$4-$5-$6");} // And insert "-" after parts of size 8,4,4,4,
                                                                            // and return it as result




                                                                            share











                                                                            $endgroup$
















                                                                              0












                                                                              0








                                                                              0





                                                                              $begingroup$

                                                                              Java 11, 152 149 bytes





                                                                              s->{var t=new java.math.BigInteger(s.replace("-",""),16);return(t.add(t.ONE).toString(16)).replaceAll("(.{4})".repeat(5)+"(.*)","$1$2-$3-$4-$5-$6");}


                                                                              Try it online.



                                                                              Explanation:



                                                                              s->{                              // Method with String as both parameter and return-type
                                                                              var t=new java.math.BigInteger( // Create a BigInteger
                                                                              s.replace("-",""), // Of the input-string with all "-" removed
                                                                              16); // Converted from Hexadecimal
                                                                              return(t.add(t.ONE) // Add 1
                                                                              .toString(16)) // And convert it back to a Hexadecimal String
                                                                              .replaceAll("(.{4})".repeat(5)+"(.*)",
                                                                              // And split the string into parts of sizes 4,4,4,4,4,rest
                                                                              "$1$2-$3-$4-$5-$6");} // And insert "-" after parts of size 8,4,4,4,
                                                                              // and return it as result




                                                                              share











                                                                              $endgroup$



                                                                              Java 11, 152 149 bytes





                                                                              s->{var t=new java.math.BigInteger(s.replace("-",""),16);return(t.add(t.ONE).toString(16)).replaceAll("(.{4})".repeat(5)+"(.*)","$1$2-$3-$4-$5-$6");}


                                                                              Try it online.



                                                                              Explanation:



                                                                              s->{                              // Method with String as both parameter and return-type
                                                                              var t=new java.math.BigInteger( // Create a BigInteger
                                                                              s.replace("-",""), // Of the input-string with all "-" removed
                                                                              16); // Converted from Hexadecimal
                                                                              return(t.add(t.ONE) // Add 1
                                                                              .toString(16)) // And convert it back to a Hexadecimal String
                                                                              .replaceAll("(.{4})".repeat(5)+"(.*)",
                                                                              // And split the string into parts of sizes 4,4,4,4,4,rest
                                                                              "$1$2-$3-$4-$5-$6");} // And insert "-" after parts of size 8,4,4,4,
                                                                              // and return it as result





                                                                              share













                                                                              share


                                                                              share








                                                                              edited 49 secs ago

























                                                                              answered 7 mins ago









                                                                              Kevin CruijssenKevin Cruijssen

                                                                              36.3k555192




                                                                              36.3k555192






























                                                                                  draft saved

                                                                                  draft discarded




















































                                                                                  If this is an answer to a challenge…




                                                                                  • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                  • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                    Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                  • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                  More generally…




                                                                                  • …Please make sure to answer the question and provide sufficient detail.


                                                                                  • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                  draft saved


                                                                                  draft discarded














                                                                                  StackExchange.ready(
                                                                                  function () {
                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178837%2fincrement-a-guid%23new-answer', 'question_page');
                                                                                  }
                                                                                  );

                                                                                  Post as a guest















                                                                                  Required, but never shown





















































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown

































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown







                                                                                  Popular posts from this blog

                                                                                  Polycentropodidae

                                                                                  Magento 2 Error message: Invalid state change requested

                                                                                  Paulmy