Skip to content

Instantly share code, notes, and snippets.

View zmuranaka's full-sized avatar

Zachary Muranaka zmuranaka

View GitHub Profile
@zmuranaka
zmuranaka / collatz.cpp
Last active August 1, 2021 15:22
Prompts the user for a number and traces its path in the Collatz conjecture sequence
#include <iostream>
// Defines one step in the Collatz conjecture sequence
// Read more about it here: https://en.wikipedia.org/wiki/Collatz_conjecture
int collatz(int n)
{
return n % 2 ? n * 3 + 1 : n / 2;
}
int main()
@zmuranaka
zmuranaka / Ackermann.cpp
Last active May 4, 2021 18:51
Prompts the user for two integers and returns the result of those from the Ackermann–Péter function
#include <iostream>
// Defines the Ackermann–Péter function.
// Read more about it and the Ackermann function in general here: https://en.wikipedia.org/wiki/Ackermann_function
int Ackermann(int m, int n)
{
if (m == 0) return n+1;
else if (n == 0) return Ackermann(m-1, 1);
else return Ackermann(m-1, Ackermann(m, n-1));
}
@zmuranaka
zmuranaka / createJar.md
Created May 9, 2020 16:48
How to create a jar file from the command prompt

Create a Jar from Command Prompt

1. Navigate to the Directory that Contains the Java Source Files

cd src

2. Compile the Java Source Files

@zmuranaka
zmuranaka / prime.cpp
Last active June 25, 2020 18:38
C++ algorithm that finds and prints all prime numbers between two integers
#include <iostream>
#include <cmath>
int main()
{
int integer1;
int integer2;
bool numberIsPrime;
std::cout << "Enter an integer: ";
@zmuranaka
zmuranaka / smoothScroll.js
Last active May 6, 2020 14:07
Simple trick to do a smooth scroll with vanilla JavaScript
// Recursive function that does a smooth scroll
function smoothScroll()
{
// We scroll again if we are not within 6 pixels of the destination
if(window.pageYOffset < positionToScrollTo - 6 || window.pageYOffset > positionToScrollTo)
{
// The setTimeout creates the smooth scroll effect
setTimeout(function()
{
window.scrollBy(0, window.pageYOffset < positionToScrollTo ? 6 : -6); // Scroll by 6 pixels