Skip to content

Instantly share code, notes, and snippets.

@Haiderahandali
Haiderahandali / main.cpp
Last active December 3, 2022 20:08
Linear Algebra Way to solve Advent of Code Day 6
typedef int s32;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef float f32;
typedef double f64;
#define ARRAY_COUNT(Array) (sizeof(Array)/ sizeof(Array[0]))
@Haiderahandali
Haiderahandali / array.c
Created January 31, 2022 18:34
Matrix Multiplication recursively
#include "array.h"
array_int array_int_create(size_t n)
{
array_int a;
if(n < 1) n = 1;
int* mem_pool = (int*) malloc(sizeof(int) * n);
if(mem_pool == NULL)
{
printf("init vector malloc failed...\n");
@Haiderahandali
Haiderahandali / links.cpp
Created December 2, 2021 11:12
a prototype for proposed design for my flow-chart app
@Haiderahandali
Haiderahandali / drawing_curve.cpp
Last active September 14, 2021 02:50
De Casteljau Bezier Curves
//------------------- Bezier Curve implementation --------------------------//
//------------------- This App Needs SDL and SDL_Image library to run -----//
//------------------- The Algorithm itself is inside drawCurve function --//
//------------------- A demo of the app is at:
//------------------- https://streamable.com/687dmw --------------------//
#include "src/core.h"
#include <SDL.h>
#include <SDL_image.h>
'''Method one using tree traversal'''
def parentheses(depth,count=0,acc='',full=None):
if full is None:
full = []
if count > 0:
parentheses(depth,count-1,acc+')',full)
if depth > 0:
parentheses(depth-1,count+1,acc+'(',full)
@Haiderahandali
Haiderahandali / splitwords.c
Last active July 27, 2021 13:06
splitting lines into multiple words for each line
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define START_LINE_SIZE 4
#define MAX_WORDS_PER_LINE 20
#define MAX_WORD_SIZE 256
typedef struct words_t
{
@Haiderahandali
Haiderahandali / linkedliststr.c
Last active July 25, 2021 22:42
doubly linked list for string
#include "linkedliststr.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
linked_list_str_t* CreateLinkedListStr(char* key)
{
linked_list_str_t* temp = malloc(sizeof(linked_list_str_t));
temp->head = malloc(sizeof(StrNode));
@Haiderahandali
Haiderahandali / main.c
Last active July 29, 2021 21:52
bracket validation
#include "stack.h"
#include "validbracket.h"
#define STACK_MAX_SIZE 100
int main(int argc, char **argv) {
if (argc != 2) {
printf("usage:\nProvide a single argument as a string for bracket matching "
" program\n");
return 0;
}
@Haiderahandali
Haiderahandali / validParenthesisUsingStack.c
Last active July 24, 2021 20:52
leetcode problem, valid parenthesis
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#define STACK_MAX_SIZE 10000
typedef struct mystack_t {
unsigned int SP;
unsigned int size;
@Haiderahandali
Haiderahandali / hashtable.c
Last active July 18, 2021 13:22
Hashtable in C
#include "hashtable.h"
int Hash(char* key, ulong_t seed)
{
ulong_t h = seed;
// this function is copied from stack over flow https://stackoverflow.com/a/629127
while (*key)
{
h = h * 101 + (unsigned)*key++;