Skip to content

Instantly share code, notes, and snippets.

@javajawa
Created October 21, 2018 08:45
Show Gist options
  • Save javajawa/d31ca4dba68e64f7ea4b0ca6cbd1ca74 to your computer and use it in GitHub Desktop.
Save javajawa/d31ca4dba68e64f7ea4b0ca6cbd1ca74 to your computer and use it in GitHub Desktop.
Shortest Euclid Solver

This piece of code came out of a challenge to write a euclid solving tool in C in as few source code bytes as possible.

It has been tested as compiling on gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516

main(a,b,c){for(scanf("%d%d",&a,&b);c=a%b;a=b,b=c);return b;}
echo 'main(a,b,c){for(scanf("%d%d",&a,&b);c=a%b;a=b,b=c);return b;}' | gcc -o euclid -x c -
echo '7 21' | ./euclid; test $? -eq 7 && echo "PASS" || echo "FAIL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment