Skip to content

Instantly share code, notes, and snippets.

@georgemorgan
Last active January 15, 2020 00:39
Show Gist options
  • Save georgemorgan/20516131a0212cf3f316 to your computer and use it in GitHub Desktop.
Save georgemorgan/20516131a0212cf3f316 to your computer and use it in GitHub Desktop.
#define z(x) strlen(x)
#define d(x) *(char*)(x)
#define i(x) d(x++)
int t;int c(char*o,char*q){if(*o>9){if(o==q){memmove(q+1,q,++t);d(q)=0;o++;}*o-=10;d(o-1)+=1;c(o-1,q);}}void f(char*a,char*b,char*o){char*l,*s,*q=o;int la,lb,ls;((la=z(a))>(lb=z(b)))?(l=a,s=b):(l=b,s=a);ls=z(s);t=z(l);while((i(o)=i(l)-'0')+'0');o=q+t-1;while(ls--){d(o--)+=d(s+ls)-'0';c(o+1,q);}o=q;while(i(o)+='0');q[t]=0;}
@Hammerstein
Copy link

Hammerstein commented Jun 7, 2016

Saved you 31 characters.

#define y char*
#define z(x) strlen(x)
#define d(x) *(y)(x)
#define i(x) d(x++)
#define w while
int t;y c(y o,y q){if(*o>9){if(o==q){memmove(q+1,q,++t);d(q)=0;o++;}*o-=10;d(o-1)+=1;c(o-1,q);}}y f(y a,y b,y o){y l,*s,*q=o;int m;(z(a)>z(b))?(l=a,s=b):(l=b,s=a);m=z(s);t=z(l);w((i(o)=i(l)-48)+48);o=q+t-1;w(m--){d(o--)+=d(s+m)-48;c(o+1,q);}o=q;w(i(o)+=48);q[t]=0;}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment