Skip to content

Instantly share code, notes, and snippets.

View nbervar21's full-sized avatar
🤔
thinking

nbervar21

🤔
thinking
View GitHub Profile
@nbervar21
nbervar21 / butils.c
Last active November 14, 2019 23:24
one-line util stuff (kinda)
#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);}
@nbervar21
nbervar21 / tic-tac-toe.c
Last active November 10, 2020 14:32
Compact tic tac toe (C)
#include <stdio.h>
#define EMPTY -1
// translate human-readable coordinates to char indexes on board
int translateRow[4] = {EMPTY, 22, 42, 62};
int translateCol[4] = {EMPTY, 0, 2, 4};
char currentPiece[2] = "OX";
// ---- translateWinConditions explanation ----
// 9 is for the squares on the board, as follows
@nbervar21
nbervar21 / credit_oneline.c
Last active October 25, 2019 20:08
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++)
@nbervar21
nbervar21 / mario_oneline.c
Last active October 17, 2019 20:03
cs50 oneline mario
// mario.c by Nick Bervar (2019)
#include <stdio.h>
#include <stdlib.h>
int main(int c, char *v[])
{
for (int i = 1, s = c > 1 ? atoi(v[1]) : 6, g = c > 2 ? atoi(v[2]) : 2; i <= s; i++)
{
for (int j = 1, m = g + (s * 2); j <= m + 1; j += (printf(j < m + 1 ? ((j <= s - i || j > s + g + i || (j > s && j <= s + g)) ? " " : "#") : "\n") * 0) + 1);
}
@nbervar21
nbervar21 / caesar_emoji_check50.c
Created December 12, 2018 01:35
caesar.c - emoji versions
// original version - passes check50 and style50
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define 👌 int
#define 🔒 "Usage: ./caesar k\n"
#define 🍑 strlen
@nbervar21
nbervar21 / caesar_oneline.c
Last active December 6, 2018 00:55
caesar_oneline.c - compact caesar cipher in c
#include <cs50.h> // caesar_oneline.c by Nick "the one-line god" Bervar
#include <stdio.h>
int main(int c, char *v[])
{
for (char i = ((c == 2) ? 0 : ((printf("Usage: ./caesar k\n") * 0) + INT_MAX)), *p = (c == 2) ? get_string("plaintext: ") : ""; p[(int)i] != '\0'; i += ((int)i == INT_MAX) ? 0 : ((printf("%s%c%s", (i < 1) ? "ciphertext: " : "", ((p[(int)i] >= 'A' && p[(int)i] <= 'Z') || (p[(int)i] >= 'a' && p[(int)i] <= 'z')) ? (p[(int)i] - ((p[(int)i] - 'A') % ('a' - 'A'))) + ((((p[(int)i] - 'A') % ('a' - 'A')) + atoi(v[c == 2 ? 1 : 0])) % 26) : p[(int)i], (p[(int)i + 1] != '\0') ? "" : "\n") * 0) + 1));
}
@nbervar21
nbervar21 / chess.c
Last active December 6, 2018 23:14
chess.c - semi-working prototype
// chess.c by Nick Bervar
#include <cs50.h>
#include <stdio.h>
// only used for printBox, temporary
#include <string.h>
// ==============================
// === preprocessor constants ===
// ==============================
@nbervar21
nbervar21 / credit_improved.c
Created November 18, 2018 18:54
cs50 - credit card number validator written entirely in emojis
//🙂🔫
#include <stdio.h>
#include <cs50.h>
#include <math.h>
#define 👌 int
#define 🍐 1
#define 🔒 "Number: "
#define 🍑 10