Skip to content

Instantly share code, notes, and snippets.

@nbervar21
Last active October 25, 2019 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbervar21/efa47ed97291204840282719f4e6e846 to your computer and use it in GitHub Desktop.
Save nbervar21/efa47ed97291204840282719f4e6e846 to your computer and use it in GitHub Desktop.
cs50 oneline credit
// credit.c by Nick Bervar (2019)
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
long long c = 0, t = 0;
for (; c < 1; c = get_long_long("Number: "));
for (int i = 1, q = c; l = log10(c); i < l; i++)
{
q /= (10 + ((t += ((q % 10) * (((i % 2) == 0) ? 2 : 1)) - (((i % 2) == 0 && ((q % 10) * 2) > 9) ? 9 : 0)) * 0));
}
printf(((t % 10) != 0) ? "INVALID\n" : (((log10(c) == 14) && (c / pow(10, log10(c) - 1) == 34 || c / pow(10, log10(c) - 1) == 37)) ? "AMEX\n" : (((log10(c) == 15) && (c / pow(10, log10(c)) == 5 && (c / (int) pow(10, log10(c) - 1)) % 10 > 0 && (c / (int) pow(10, log10(c) - 1)) % 10 < 6)) ? "MASTERCARD" : (((log10(c) == 12 || log10(c) == 15) && (c / pow(10, log10(c)) == 4)) ? "VISA\n" : "INVALID\n"))));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment