Skip to main content
remember history
Source Link
AShelly
  • 4.7k
  • 1
  • 22
  • 38

C, 11x1212x8 = 96

Inspired by @ciamej, I've reduced it. It uses that divide by 3 trick, plus the realization that the carpet effectively converts an if into a while loop.

The code was tested on gcc/Ubuntu for iterations up to 3.

#ifndef A //
#define A //
x;main(a){//
a++;/*    */
if(a/=3)x++;
printf(   //
"%d",x);} //
#endif    //

Previous Solution: C, 11x12

Not a size winner, but hey, it's C.

It finds log2 of the blockcount by bitshifting, then uses some magic numbers and int truncation to estimate log3. The math should work up to 26 iterations (a 42 bit number). The code was tested on gcc/Ubuntu for iterations up to 3.

#ifndef A//
#define A//
int n=0;//_
int main//_
(v,c){//___
n+=1;/*..*/
while(n//__
>>=1)v++;//
n=.3+.62*v;
printf(//__
"%d",n);}//
#endif//__

C, 11x12

Not a size winner, but hey, it's C.

It finds log2 of the blockcount by bitshifting, then uses some magic numbers and int truncation to estimate log3. The math should work up to 26 iterations (a 42 bit number). The code was tested on gcc/Ubuntu for iterations up to 3.

#ifndef A//
#define A//
int n=0;//_
int main//_
(v,c){//___
n+=1;/*..*/
while(n//__
>>=1)v++;//
n=.3+.62*v;
printf(//__
"%d",n);}//
#endif//__

C, 12x8 = 96

Inspired by @ciamej, I've reduced it. It uses that divide by 3 trick, plus the realization that the carpet effectively converts an if into a while loop.

The code was tested on gcc/Ubuntu for iterations up to 3.

#ifndef A //
#define A //
x;main(a){//
a++;/*    */
if(a/=3)x++;
printf(   //
"%d",x);} //
#endif    //

Previous Solution: C, 11x12

Not a size winner, but hey, it's C.

It finds log2 of the blockcount by bitshifting, then uses some magic numbers and int truncation to estimate log3. The math should work up to 26 iterations (a 42 bit number).

#ifndef A//
#define A//
int n=0;//_
int main//_
(v,c){//___
n+=1;/*..*/
while(n//__
>>=1)v++;//
n=.3+.62*v;
printf(//__
"%d",n);}//
#endif//__
formatting
Source Link
AShelly
  • 4.7k
  • 1
  • 22
  • 38

C, 11x12

C, 11x12

Not a size winner, but hey, it's C.

It finds log2 of the blockcount by bitshifting, then uses some magic numbers and int truncation to convert to estimate log3. ShouldThe math should work up to 26 iterations (a 42 bit number). TestedThe code was tested on GCCgcc/Ubuntu for iterations up to 3.

#ifndef A//
#define A//
int n=0;//_
int main//_
(v,c){//___
n+=1;/*..*/
while(n//__
>>=1)v++;//
n=.3+.62*v;
printf(//__
"%d",n);}//
#endif//__
#ifndef A//
#define A//
int n=0;//_
int main//_
(v,c){//___
n+=1;/*..*/
while(n//__
>>=1)v++;//
n=.3+.62*v;
printf(//__
"%d",n);}//
#endif//__

C, 11x12

Not a size winner, but hey, it's C.

It finds log2 of the blockcount by bitshifting, then uses some magic numbers and int truncation to convert to log3. Should work up to 26 iterations (a 42 bit number). Tested on GCC/Ubuntu up to 3.

#ifndef A//
#define A//
int n=0;//_
int main//_
(v,c){//___
n+=1;/*..*/
while(n//__
>>=1)v++;//
n=.3+.62*v;
printf(//__
"%d",n);}//
#endif//__

C, 11x12

Not a size winner, but hey, it's C.

It finds log2 of the blockcount by bitshifting, then uses some magic numbers and int truncation to estimate log3. The math should work up to 26 iterations (a 42 bit number). The code was tested on gcc/Ubuntu for iterations up to 3.

#ifndef A//
#define A//
int n=0;//_
int main//_
(v,c){//___
n+=1;/*..*/
while(n//__
>>=1)v++;//
n=.3+.62*v;
printf(//__
"%d",n);}//
#endif//__
Source Link
AShelly
  • 4.7k
  • 1
  • 22
  • 38

C, 11x12

Not a size winner, but hey, it's C.

It finds log2 of the blockcount by bitshifting, then uses some magic numbers and int truncation to convert to log3. Should work up to 26 iterations (a 42 bit number). Tested on GCC/Ubuntu up to 3.

#ifndef A//
#define A//
int n=0;//_
int main//_
(v,c){//___
n+=1;/*..*/
while(n//__
>>=1)v++;//
n=.3+.62*v;
printf(//__
"%d",n);}//
#endif//__