Skip to content

Instantly share code, notes, and snippets.

@leomastoras
Created April 14, 2024 09:31
Show Gist options
  • Save leomastoras/5079dfa82423c5dd82bf1079d114c5a9 to your computer and use it in GitHub Desktop.
Save leomastoras/5079dfa82423c5dd82bf1079d114c5a9 to your computer and use it in GitHub Desktop.
Single (ONE) statement to generate 100k random smith numbers
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define COMPUTATIONS 100000
int c,G,o,d,S,k,i,L,l;
int main(int n,char **v){for(!(n=v?0:n)?srand(c=time(NULL)),printf("Current time is %d\n\n",c),k=L=0:n<0||(S=0);i!=COMPUTATIONS?1:(printf("\nFound %.2f%% Smith numbers\n",(double)L*100/COMPUTATIONS),0);!n?d=2,G=4,main(o=l=((rand()%32768)+1)*((rand()%32768)+1)+1,NULL)?printf("%10d is a Smithnumber\n",l,L++):0,i++:(n<0||!(n%d)?k=d,main(-1,NULL),n/=d:(d+=d<5?d-1:(G=6-G))))if(!n?0:(d*d>n))return n<0?!k||(!(n+1)?S-=k%10:(S+=k%10),k/=10,main(n,NULL)):(S&&n-1?k=n,main(-1,NULL),k=o,main(-1337,NULL),!S:0);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment