Skip to content

Instantly share code, notes, and snippets.

@naezith
naezith / fifa2014.c
Last active July 15, 2017 01:13
2014 Fifa World Cup Simulation, Full C Source Code
// This code is pretty old so there might be very useless/wrong stuff.
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
struct Team {
@naezith
naezith / merge_sorted_arrays.c
Last active January 4, 2016 11:34
Merge two sorted arrays as a single sorted array
#include <stdio.h>
struct DynamicArray {
int* arr;
unsigned short size, cursor; //To track cursor's position
};
int main() {
struct DynamicArray arrays[3] = {NULL, 0, 0};
unsigned short i, j; //Loop counters
@naezith
naezith / cached_fibonacci.c
Created January 4, 2016 11:36
Fibonacci function uses cache
#include <stdio.h>
int fibonacci (int n); // Calculates the n'th fibonacci number
// main function
int main (void) {
int n = 1337;
printf ("Fibonacci Number Calculator - Tolga Ay - 13011057\n\n\n\nEnter a negative number or zero to quit.\n\n");
while (1) {
@naezith
naezith / playfair.c
Created January 4, 2016 11:42
Playfair Cipher
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct COORDS {
int r;
int c;
} COORD;
void erase (char s[], int idx); //Erases the given element of the string
@naezith
naezith / threaded_walker.c
Created January 4, 2016 11:47
Threaded File Walker
// This code walks through text files which including "marks", calculates average of them in threads
#include <pthread.h>
#include <dirent.h>
#include <regex.h>
#include <stdio.h>
// Walks through all files, counts them and saves the directories to fileNames list
int getFileNames(const char* dir, const char* pattern, const char** * fileNamesOut, short* fileCountOut);
// Error Codes
@naezith
naezith / huffman.c
Last active March 25, 2018 09:19
Huffman Encoding
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct Character {
unsigned char val;
int freq;
} CHARACTER;
struct TREENODE {
@naezith
naezith / shortest_word_distance.c
Created January 4, 2016 12:15
Shortest word distance by changing letters using graph
#include <stdio.h>
// FILE INPUT INFO
#define N 2420 // Number of words
#define WORD_LEN 5 // Character count of a word
// INPUTS
#define VALIDATE_GRAPH_CREATION 1
#define SRC_WORD "prove" // Word to start searching
#define DEST_WORD "guess" // Word to find
@naezith
naezith / password_cracker.c
Created January 4, 2016 12:21
Brute Force Password Cracker
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#define PASSWORD_TO_CRACK "vK6b"
// Increment the lowest digit by 1, check if it passed the last character in the char set
int incrementPass(char* password, int maxChar, int currLength) {
++password[0];
@naezith
naezith / filter_list.sh
Created January 4, 2016 12:30
Filter a list of data
inf="input_list.txt" # this file has lines like [201504695,ASLI,ASLAN,[email protected],CS101,89,2]
outf="list.txt"
sep=',' #define seperator
#filter the list
list=$(cat $inf `
`| egrep "2015.*(CS101|CS102),([6-9][0-9]|100).*" ` # filter with CS101 OR CS102, 2015 and 60 <= mark
`| sed 's/-//1' ` # remove - from the number
`| awk -F $sep 'int($7)==2' ` # second time they take the lesson
`| awk -F $sep 'int($6)<90' ` # mark < 90
@naezith
naezith / quicksort.c
Created January 4, 2016 12:33
Benchmark of Quicksort implementations
// You need to uncomment and comment some blocks in order to benchmark, it is not full automatic.
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
// Inputs
#define ARRAY_SIZE 1000
#define LOGS_ON 0