Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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,a.aslan@ce1.yildiz.edu.tr,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 / round_robin.c
Last active January 4, 2016 12:35
Round Robin process scheduling simulation
#include <stdio.h>
#include <stdlib.h>
typedef struct Process {
unsigned int id;
int cpu_time;
int last_start_time;
int preemption_count;
} Process;
@naezith
naezith / text_justify.c
Last active January 4, 2016 12:44
Text Justify
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
int main(){
char words[100][100];
int word_count = 0, line_length;
@naezith
naezith / course_catalog_1.dtd
Created January 4, 2016 12:50
Course Catalog DTD examples
<!DOCTYPE Course_Catalog [
<!ELEMENT Course_Catalog (Department+)>
<!ELEMENT Department (Title,Course*,Professor*,Lecturer*)>
<!ELEMENT Professor (First_Name,Middle_Initial?,Last_Name)>
<!ELEMENT Lecturer (First_Name,Middle_Initial?,Last_Name)>
<!ELEMENT Course (Title,Description?)>
<!ELEMENT Description (#PCDATA | Courseref)*>
<!ELEMENT Courseref EMPTY>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT First_Name (#PCDATA)>
@naezith
naezith / maze.c
Created January 4, 2016 12:52
Find Path in Maze using Depth First Search, DFS
#include <stdio.h>
#include <conio.h>
#define SIZE_X 6
#define SIZE_Y 6
// Visibility and Walls around
typedef struct CELL { char mid, N, E, S, W; } CELL;
CELL maze[SIZE_X][SIZE_X];