Skip to main content
Commonmark migration
Source Link

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!


###Proof of concept that this works with MP arithmetic:

Proof of concept that this works with MP arithmetic:

C# (Mono C# compiler), 187 165 bytes

(143 bytes + 22 bytes for the using System.Numerics; in the header)

q=>{var r="";for(int j=0,h=q+1,k;j<q;r+=((BigInteger.Pow(10,k)-1)*BigInteger.Pow(10,j%2*(q-k))).ToString("D"+q)+"\n")k=++j>h/2?h-j:j;return r;} 

Try it online!

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!


###Proof of concept that this works with MP arithmetic:

C# (Mono C# compiler), 187 165 bytes

(143 bytes + 22 bytes for the using System.Numerics; in the header)

q=>{var r="";for(int j=0,h=q+1,k;j<q;r+=((BigInteger.Pow(10,k)-1)*BigInteger.Pow(10,j%2*(q-k))).ToString("D"+q)+"\n")k=++j>h/2?h-j:j;return r;} 

Try it online!

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!


Proof of concept that this works with MP arithmetic:

C# (Mono C# compiler), 187 165 bytes

(143 bytes + 22 bytes for the using System.Numerics; in the header)

q=>{var r="";for(int j=0,h=q+1,k;j<q;r+=((BigInteger.Pow(10,k)-1)*BigInteger.Pow(10,j%2*(q-k))).ToString("D"+q)+"\n")k=++j>h/2?h-j:j;return r;} 

Try it online!

Code shortening
Source Link
ErikF
  • 4.8k
  • 9
  • 11

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!


###Proof of concept that this works with MP arithmetic:

C# (Mono C# compiler), 187187 165 bytes

(165143 bytes + 22 bytes for the using System.Numerics; in the header)

q=>{var r="";var t=BigInteger.One*10;forr="";for(int j=0,h=q+1,k;j<q;r+=((BigInteger.Pow(t10,k)-1)*BigInteger.Pow(t10,j%2*(q-k))).ToString("D"+q)+"\n")k=++j>h/2?h-j:j;return r;} 

Try it online!Try it online!

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!


###Proof of concept that this works with MP arithmetic:

C# (Mono C# compiler), 187 bytes

(165 bytes + 22 bytes for the using System.Numerics; in the header)

q=>{var r="";var t=BigInteger.One*10;for(int j=0,h=q+1,k;j<q;r+=((BigInteger.Pow(t,k)-1)*BigInteger.Pow(t,j%2*(q-k))).ToString("D"+q)+"\n")k=++j>h/2?h-j:j;return r;} 

Try it online!

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!


###Proof of concept that this works with MP arithmetic:

C# (Mono C# compiler), 187 165 bytes

(143 bytes + 22 bytes for the using System.Numerics; in the header)

q=>{var r="";for(int j=0,h=q+1,k;j<q;r+=((BigInteger.Pow(10,k)-1)*BigInteger.Pow(10,j%2*(q-k))).ToString("D"+q)+"\n")k=++j>h/2?h-j:j;return r;} 

Try it online!

Additional code test
Source Link
ErikF
  • 4.8k
  • 9
  • 11

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!


###Proof of concept that this works with MP arithmetic:

C# (Mono C# compiler), 187 bytes

(165 bytes + 22 bytes for the using System.Numerics; in the header)

q=>{var r="";var t=BigInteger.One*10;for(int j=0,h=q+1,k;j<q;r+=((BigInteger.Pow(t,k)-1)*BigInteger.Pow(t,j%2*(q-k))).ToString("D"+q)+"\n")k=++j>h/2?h-j:j;return r;} 

Try it online!

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!

C (gcc), 118 108 bytes

This one isn't going to win, but it's a different approach (or at least, I think so!) Instead of doing string manipulations, I make use of the fact that \$10^x-1\$ over \$[1..n] = \{9, 99, 999, ...\}\$, which then can be multiplied to get the appropriate pattern; printf() then does the zero-padding for right-justification.

Sadly, int only has sufficient range to do up to 9 digits (on 32-bit platforms), so you need to go to long for larger patterns; a language that natively does MP arithmetic might be able to use this for something.

Thanks to ceilingcat for the suggestion.

h,j,k;p(h){h=h?10*p(--h):1;}f(i){for(j=0,h=i++;k=++j>i/2?i-j:j,j<i;printf("%0*d\n",h,~-p(k)*p(j%2*(h-k))));} 

Try it online!


###Proof of concept that this works with MP arithmetic:

C# (Mono C# compiler), 187 bytes

(165 bytes + 22 bytes for the using System.Numerics; in the header)

q=>{var r="";var t=BigInteger.One*10;for(int j=0,h=q+1,k;j<q;r+=((BigInteger.Pow(t,k)-1)*BigInteger.Pow(t,j%2*(q-k))).ToString("D"+q)+"\n")k=++j>h/2?h-j:j;return r;} 

Try it online!

Code shortening
Source Link
ErikF
  • 4.8k
  • 9
  • 11
Loading
Source Link
ErikF
  • 4.8k
  • 9
  • 11
Loading