Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Implementation of Gary's Formula as described on http://ludix.com/moriarty/psalm46.html
- /* v1.1 - slight revision/optimization:
- * inlined get_code() and parse_arg() functions
- * removed excessive multiplication (distributive property)
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <ctype.h>
- uint64_t
- get_sum(char *arg)
- {
- uint64_t sum = 0;
- for(; *arg; arg++)
- sum += isalpha(*arg) ? toupper(*arg) - '@' : 0;
- return sum * 6;
- }
- void
- parse_args(char **args)
- {
- for(; *args; args++)
- printf("%s: %lu\n", *args, get_sum(*args));
- }
- void
- usage(void)
- {
- fputs("usage: gary <string>\n", stderr);
- exit(1);
- }
- int
- main(int argc, char **argv)
- {
- if(argv[1])
- parse_args(argv + 1);
- else
- usage();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement