Last active
November 14, 2019 23:24
-
-
Save nbervar21/2fecb98084689e2d88f9ac11a907c059 to your computer and use it in GitHub Desktop.
one-line util stuff (kinda)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
int isLower(char chr) {return chr >= 'a' && chr <= 'z';} | |
int isUpper(char chr) {return chr >= 'A' && chr <= 'Z';} | |
int isAlpha(char chr) {return isUpper(chr) || isLower(chr);} | |
char toLower(char chr) {return isUpper(chr) ? chr - ('A' - 'a') : chr;} | |
char toUpper(char chr) {return isLower(chr) ? chr + ('A' - 'a') : chr;} | |
int fib(int n) {return n < 2 ? n ? fib(n - 1) + fib(n - 2);} | |
// nice seg fault skid lmao | |
unsigned long long hash(char *str) | |
{ | |
unsigned long long h = 0; | |
for (int i = 0; i < 8; i++) | |
{ | |
if (*(str + i) == '\0') | |
{ | |
break; | |
} | |
h += (*(str + i) * pow(sizeof(char) * 8, i)); | |
} | |
return h; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment