Project Euler #19: Counting Sundays

You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Saving February alone, Which has twenty-eight, rain or shine. And on leap years, twenty-nine. A …

Solving a second order linear homogenous recurrence relation with consistent coefficients

#include <iostream> #include <vector> #include <math.h> // Solves for quadratic formula std::vector quadraticCalc(double a, double b, double c); int main(void) { double A = 0, B = 0, Cone, Ctwo; std::vector<double> terms, quadBuff; std::cout << “Enter value for a_(0): “; std::cin >> A; terms.push_back(A); std::cout << std::endl; std::cout << “Enter …

Divide by two to convert decimal to binary

Simple C++ program that converts from decimal to binary by dividing a given number by two repeatedly, saving the remainder to a boolean vector, and then printing the contents of the vector back. #include <iostream> #include <vector> //////////////////////////////////////////////////////////////////////// void printBinary(std::vector passedBool); // std::vector divisionAlgorithm(unsigned long long userInput); // //////////////////////////////////////////////////////////////////////// int …

GCD using Euclidean Algorithm

Given two unsigned long long, x and y, such that x is greater than y… Throughout the algorithm, x = (y * quotient) + remainder void gcdCalc(unsigned long long x, unsigned long long y) { unsigned long long remainder; // While y != 0 while(y) { std::cout

Prime factor finder

#include <iostream> #include <vector> #include <math.h> #include &ltalgorithm> int main(void) { // ull is large data type to input large numbers unsigned long long inputNumb, sieveMax; // for holding found numbers; easy way to sort ascending std::vector&ltunsigned long long&gt foundNumbers; // flag for ending division in prime factorization bool divided; …

Full adder simulation

A full adder simulation implementation in C++. It is implemented with a “adder queue” as part of the assignment prerequisites was adding 8 binary strings to a buffer for adding. #include <iostream> #include <vector> #include <algorithm> //////////////////////////////////////////////////////////////////////////////// // Function Prototypes //////////////////////////////////////////////////////////////////////////////// std::string fullAdder(std::vector<std::vector*> adderIn); int userActivity(std::string stringBuff[9], std::vector<std::vector*> &adderInput); void …

Calculating nth Fibonacci number

This is simply an implementation of Binet’s formula in C++; someone had a question regarding calculating Fibonacci numbers from the nth number, backwards, so I created this small program. It calculates Fibonacci numbers from the 50th, down to the 1st, in reverse. Python would allow for greater Fibonacci sequence calculations …