Project Euler #7: 10001st prime

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number?   I utilized a Sieve of Erastothenes with a bit vector implemented in C++ to solve this problem. The answer …

CSAPP 4.47 – Y86-64 bubblesort

Your assignment will be to write a Y86-64 program to perform bubblesort. For reference, the following C function implements bubblesort using array referencing: /* Bubble sort: Array version */ void bubble_a(long *data, long count) { long i, last; for(last = count-1; last > 0; last–){ for( i = 0; i …

CSAPP Direct Caching Simulator Lab Solution

  /* Sources: http://www.gnu.org/software/libc/manual/html_node/Getopt.html https://en.wikipedia.org/wiki/C_dynamic_memory_allocation Computer Systems A Programmers Perspective */ #include <stdlib.h> #include <stdio.h> #include <getopt.h> #include “cachelab.h” #include <math.h> #include <strings.h> typedef unsigned long long int address; typedef int bool; #define true 1 #define false 0 typedef struct // Structure for holding command line parameters given when calling …

Project Euler #22: Names scores

Using names.txt (right click and ‘Save Link/Target As…’), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. For example, …

Project Euler #15: Lattice Paths

Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. How many such routes are there through a 20×20 grid? This problem is solvable via combinatorics; since you are …

Linked List Exercise in C++

#include #include using namespace std; struct Node { char _data; Node *_next; Node() { this->_next = 0; this->_data = 0; } Node(char ch) { this->_data = ch; this->_next = 0; } ~Node() { } }; class LinkedList { private: Node *_header; int listCount; public: LinkedList(); ~LinkedList(); Node *getHeader(); void setHeader(Node …

Linked List Exercise in C++

#ifndef _LINKED_LIST_ #define _LINKED_LIST_ #include struct Node{ // Data Link void *data; // Pointers to previous and next Node *next; }; class LinkedList { private: // Keeps count of the number of list elements int listCount; // Keeps track of the head of the list for traversal Node *head; public: …

Malloc, Realloc, and Free Implementation In C

/* Sources: Computer Systems a Programmers Perspective The C Programming Language http://danluu.com/malloc-tutorial/ http://g.oswego.edu/dl/html/malloc.html https://www.cs.cmu.edu/~fp/courses/15213-s05/code/18-malloc/malloc.c */ #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <unistd.h> #include <string.h> #include “mm.h” #include “memlib.h” /* malloc, realloc, and free implementation in C. The list is searched in a first fit manner, where the first fit …