Skip to main content
Commonmark migration
Source Link

##C, 186 183 bytes

C, 186 183 bytes

#include<stddef.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}

##C, 186 183 bytes

#include<stddef.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}

C, 186 183 bytes

#include<stddef.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}
Rollback to Revision 5
Source Link

##C, 186 183 181183 bytes

#include<math#include<stddef.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}

##C, 186 183 181 bytes

#include<math.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}

##C, 186 183 bytes

#include<stddef.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}
added 9 characters in body
Source Link

##C, 186 183183 181 bytes

#include<stddef#include<math.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}

##C, 186 183 bytes

#include<stddef.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}

##C, 186 183 181 bytes

#include<math.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

The primality test is very inefficient, so the computation will struggle a bit for n > 16 and become painfully long for n = 19. Nevertheless it works and gives the expected results.

The code assumes that size_t is a 64bit type, which is true for both 64bit Linux and Windows.


Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 33 bytes. The following version works for n <= 15 using int and is 150 byte long:

a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}

Test main:

#include <stdio.h>

int main() {
  printf("Input - Output\n");
  for (int i = 1; i < 20; ++i) {
    printf("%2d    - %ld\n", i, F(i));
  }
}
edited body
Source Link
Loading
size_t
Source Link
Loading
added 347 characters in body
Source Link
Loading
added 93 characters in body
Source Link
Loading
Source Link
Loading