Skip to main content
Commonmark migration
Source Link

#C, 82 bytes, safe

C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see https://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.

#C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see https://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.

C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see https://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

#C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see http://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bsshttps://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.

#C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see http://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.

#C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see https://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.

added 788 characters in body
Source Link
mIllIbyte
  • 1.2k
  • 8
  • 14

#C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0, which. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see http://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (the only other global variable b is initialized), and if itthus goes into the data segment). If a is not at the end of bss, then there will be at least anotherthe byte higher than the highest order byte of a. This byte has value 0 and is the highest order byte of *ba is also in bss and thus has value 0.

#C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0, which I think is true for gcc since by default uninitialized variables go into the bss segment, and initialized variables go into the data segment (see http://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (b is initialized), and if it is not at the end of bss, then there will be at least another byte higher than the highest order byte of a. This byte has value 0 and is the highest order byte of *b.

#C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is A004526, floor(n/2).

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.
And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see http://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.

added 788 characters in body
Source Link
mIllIbyte
  • 1.2k
  • 8
  • 14
Loading
added 7 characters in body
Source Link
mIllIbyte
  • 1.2k
  • 8
  • 14
Loading
added 26 characters in body
Source Link
mIllIbyte
  • 1.2k
  • 8
  • 14
Loading
added 16 characters in body
Source Link
mIllIbyte
  • 1.2k
  • 8
  • 14
Loading
Source Link
mIllIbyte
  • 1.2k
  • 8
  • 14
Loading