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]
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
struct Pixel { | |
unsigned char r; | |
unsigned char g; | |
unsigned char b; | |
}; |
“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 |
#include <stdio.h> | |
typedef struct | |
{ | |
char rgbtBlue; | |
char rgbtGreen; | |
char rgbtRed; | |
char int_padding; | |
} __attribute__((__packed__)) | |
RGBTRIPLE; |
9 | |
i | |
b | |
c | |
d | |
e | |
f | |
g | |
h | |
a |
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.
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.
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
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++) { |
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. |
const beginTime = process.hrtime(); | |
let input = ["....#...##.#.........#....#....", | |
"#.......#...#...#.#............", | |
"#..#..#.#.##....#.#........#...", | |
"........##...................#.", | |
"........#...##...#.#.###.......", | |
"##............#...#.....#.##...", | |
"...........#....###...#.....#..", | |
".......#......#..##..#.....#...", |