Skip to main content
Commonmark migration
Source Link

#VBA, 157 103 bytes

VBA, 157 103 bytes

The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Variant is the default for any undeclared variable so that's easy. Every time the right-hand side (a) rolls over, set it back to 0 and iterate the left-hand side (b) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a rolls over. This has a smaller max than the string method but it's well above 2^128.

Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub

Once it's formatted for humans, it looks like this:

Sub c()
    Do
        a = a + 1
        If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
        Debug.Print b & Format(a, f)
    Loop
End Sub

Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub

#VBA, 157 103 bytes

The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Variant is the default for any undeclared variable so that's easy. Every time the right-hand side (a) rolls over, set it back to 0 and iterate the left-hand side (b) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a rolls over. This has a smaller max than the string method but it's well above 2^128.

Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub

Once it's formatted for humans, it looks like this:

Sub c()
    Do
        a = a + 1
        If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
        Debug.Print b & Format(a, f)
    Loop
End Sub

Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub

VBA, 157 103 bytes

The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Variant is the default for any undeclared variable so that's easy. Every time the right-hand side (a) rolls over, set it back to 0 and iterate the left-hand side (b) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a rolls over. This has a smaller max than the string method but it's well above 2^128.

Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub

Once it's formatted for humans, it looks like this:

Sub c()
    Do
        a = a + 1
        If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
        Debug.Print b & Format(a, f)
    Loop
End Sub

Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub
added 67 characters in body
Source Link
Engineer Toast
  • 9.5k
  • 1
  • 23
  • 53

#VBA, 157 103 bytes

The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Variant is the default for any undeclared variable so that's easy. Every time the right-hand side (a) rolls over, set it back to 0 and iterate the left-hand side (b) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a rolls over. This has a smaller max than the string method but it's well above 2^128.

Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub

Once it's formatted for humans, it looks like this:

Sub c()
    Do
        a = a + 1
        If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
        Debug.Print b & Format(a, f)
    Loop
End Sub

Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub

#VBA, 157 103 bytes

The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Every time the right-hand side (a) rolls over, set it back to 0 and iterate the left-hand side (b) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a rolls over. This has a smaller max than the string method but it's well above 2^128.

Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub

Once it's formatted for humans, it looks like this:

Sub c()
    Do
        a = a + 1
        If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
        Debug.Print b & Format(a, f)
    Loop
End Sub

Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub

#VBA, 157 103 bytes

The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Variant is the default for any undeclared variable so that's easy. Every time the right-hand side (a) rolls over, set it back to 0 and iterate the left-hand side (b) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a rolls over. This has a smaller max than the string method but it's well above 2^128.

Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub

Once it's formatted for humans, it looks like this:

Sub c()
    Do
        a = a + 1
        If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
        Debug.Print b & Format(a, f)
    Loop
End Sub

Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub
Switched to using Variant/Decimal types instead of strings
Source Link
Engineer Toast
  • 9.5k
  • 1
  • 23
  • 53

#VBA, 157157 103 bytes

The Variant / Decimal data type in VBA can only handle numeric data typesallows up to ~1.8E+308 as a Double but you lose significant29 digits because it will display and store them using scientific notation. To get around this, I use the String type that can handle up to ~2 billion charactersof precision. Since 2^128 is only 39 charactersdigits long, this should be OK. However, that means I so we have to do math on a string which gets messiersmoosh two variables together. It starts withEvery time the right-most characterhand side (a) rolls over, convertsset it back to a number,0 and then keeps movingiterate the left until-hand side (b) by 1. To handle leading zeros, we set the result is lessformat to be 28 digits long the first time that a rolls over. This has a smaller max than 10the string method but it's well above 2^128.

Sub dc()
s="1"
Do
Debug.?sa=a+1
For i=Len(s)ToIf 1Stepa=10^28Then -1
c=Valb=b+1:a=0:f=Replace(RightSpace(s,128)," ",0)+1
s=LeftDebug.?b &Format(sa,i-1f)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub

Once it's indented and automatically formatted for humans, it looks like this:

Sub dc()
    s = "1"Do
    Do
     a = a Debug.Print+ s1
        ForIf ia = Len(s) To 1 Step -1
10 ^ 28 Then b = b + 1: a = 0: cf = ValReplace(RightSpace(s28), 1))" +", 10)
           Debug.Print sb =& LeftFormat(sa, i - 1f)
       Loop
End Sub

Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c < 10 Thenc<10Then Exit For
            If i - 1 Then r = r1Then &r=r "0"&"0"
        Next
        s = s & cs=s &&c r&r
        r = ""r=""
    Loop
End Sub

#VBA, 157 bytes

VBA can only handle numeric data types up to ~1.8E+308 as a Double but you lose significant digits because it will display and store them using scientific notation. To get around this, I use the String type that can handle up to ~2 billion characters. Since 2^128 is only 39 characters long, this should be OK. However, that means I have to do math on a string which gets messier. It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub

Once it's indented and automatically formatted, it looks like this:

Sub d()
    s = "1"
    Do
        Debug.Print s
        For i = Len(s) To 1 Step -1
            c = Val(Right(s, 1)) + 1
            s = Left(s, i - 1)
            If c < 10 Then Exit For
            If i - 1 Then r = r & "0"
        Next
        s = s & c & r
        r = ""
    Loop
End Sub

#VBA, 157 103 bytes

The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Every time the right-hand side (a) rolls over, set it back to 0 and iterate the left-hand side (b) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a rolls over. This has a smaller max than the string method but it's well above 2^128.

Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub

Once it's formatted for humans, it looks like this:

Sub c()
    Do
        a = a + 1
        If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
        Debug.Print b & Format(a, f)
    Loop
End Sub

Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.

Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub
Source Link
Engineer Toast
  • 9.5k
  • 1
  • 23
  • 53
Loading