Skip to content

Instantly share code, notes, and snippets.

@nicknapoli82
nicknapoli82 / day3.js
Created December 4, 2020 14:15
AOC Day 3
const beginTime = process.hrtime();
let input = ["....#...##.#.........#....#....",
"#.......#...#...#.#............",
"#..#..#.#.##....#.#........#...",
"........##...................#.",
"........#...##...#.#.###.......",
"##............#...#.....#.##...",
"...........#....###...#.....#..",
".......#......#..##..#.....#...",
@nicknapoli82
nicknapoli82 / simple_hash.txt
Last active September 8, 2020 16:11
Very simple analysis of a couple hashing algorithms
This is just comparing my hash function against the djb2 function and xxHash.
The purpose is not only to observe speed, but also to observe dispersion into a hash table and collisions that occur
considering a full 64 bits. Maybe this is useful?
I was more focused on my own hash function which is a simple play on the djb2 algorithm.
You may find interesting the times involved based on optimization, and when it concerns unfilled buckets.
For filling buckets I am only using the low bits of the full number. So
table bucket = 64bit hash & 0xffff;
when I want to only use the first 16 bits.
@nicknapoli82
nicknapoli82 / mergeSort.c
Last active July 20, 2020 04:08
Merge Sort Modified - Sort array in place
void merge_sort(int size, int (*comparator)(int, int), int arr[]);
int increasing(int a, int b);
int decreasing(int a, int b);
int main(void) {
// int test[7] = {5, 23, 7, 26, 17, 2, 9};
int test[21] = {21, 20, 15, 17, 1, 7, 3, 1, 56, 48,
832, 38, 20, 19, 39, 40, 7, 38, 19, 28, 38};
merge_sort(21, increasing, test);
for(int i = 0; i < 21; i++) {
@nicknapoli82
nicknapoli82 / c_memory.org
Last active November 30, 2024 21:38
Everything in c is a pointer!

Everything in C is a pointer!

That’s right. I’m making this statement. This little write-up is an attempt at explaining how any why everything in the c programming language is actually just a pointer. This is simply an attempt at explaining how memory in the computer is arranged in a narrowed view and my real goal is to consider the most simple examples possible.

I will be focusing on x86 specifically.

Types in c (bits and bytes) - and pointers

I would feel pretty confident that you, by now, understand that the types in c are simply identifiers in how much space is used to represent a number. I have no interest in explaining the difference between signed vs unsigned integers. Nor am I going to explain how floating point numbers are represented. If you are interested in those things take a look at these two links. C data types and [[https://en.wikipedia.org/wiki/Floating-point_ari

@nicknapoli82
nicknapoli82 / cs50_Tideman_cycle-explanation.md
Last active December 10, 2024 18:44
My attempt at clarifying how cycles work for the Tideman algorithm

A Way to Look at Tideman Lock Pairs

I've observed that there is a little bit of a disconnect in understanding what it is that needs to be done to properly implement the lock_pairs function for cs50 Tideman. The goal of this little write-up is simply an attempt at explaining what the problem actually is, and why a cycle imposes a problem.

First:
If you are unfamiliar with the actual problem, or have not read through the entire cs50 Tideman problem description. Then I think you should start there.
cs50 Tideman

Second:
This little write-up is only narrowing in on the idea of cycles, and a way to think about what a cycle is and determine if locking a pair in the pairs array would create that cycle. This does not talk about any other part of the Tideman problem.

@nicknapoli82
nicknapoli82 / pointers.md
Last active June 15, 2022 13:59
Just a look at pointers in the c language. An attempt at clarifying what is going on in memory.

A simple look at pointers in C

Consider this simple snippet of code

int a = 5; 
int* b;
int c;
b = &c

Crudely drawn. If you think about memory like a char array. Then
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

@nicknapoli82
nicknapoli82 / Tideman_test.txt
Last active May 9, 2024 17:27
A test to use for cs50 Tideman problem. Run as "./tideman a b c d e f g h i < Tideman_test.txt"
9
i
b
c
d
e
f
g
h
a
@nicknapoli82
nicknapoli82 / struct_pointer.c
Last active May 1, 2020 05:53
A simple look at what can happen when you don't use pointers correct
#include <stdio.h>
typedef struct
{
char rgbtBlue;
char rgbtGreen;
char rgbtRed;
char int_padding;
} __attribute__((__packed__))
RGBTRIPLE;
“It doesn’t interest me what you do for a living. I want to know what you ache for, and if you dare to dream of meeting your heart’s longing. It doesn’t interest me how old you are. I want to know if you will risk looking like a fool for love, for your dream, for the adventure of being alive. It doesn’t interest me what planets are squaring your moon. I want to know if you have touched the center of your own sorrow, if you have been opened by life’s betrayals or have become shriveled and closed from fear of further pain!I want to know if you can sit with pain, mine or your own, without moving to hide it or fade it, or fix it. I want to know if you can be with joy, mine or your own, if you can dance with wildness and let the ecstasy fill you to the tips of your fingers and toes without cautioning us to be careful, to be realistic, to remember the limitations of being human. It doesn’t interest me if the story you are telling me is true. I want to know if you can disappoint another to be true to yourself; if yo
@nicknapoli82
nicknapoli82 / Pixel_Table.c
Created December 25, 2019 20:04
Create Index of Pixels combined rgb values into a unit and quantify number pixels found in an image
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Pixel {
unsigned char r;
unsigned char g;
unsigned char b;
};