This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void waitForUser () { | |
cout << "Press Enter to continue...." << endl; | |
if (cin.get() != '\n') cin.ignore(100, '\n'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bubble_sort(int Array[], int size) | |
{ | |
bool sorted = false; // assume that the array is not sorted | |
while (!sorted) | |
{ | |
bool swaped = false; | |
for (int i = 0; i < size; i++) | |
{ | |
if (Array[i] > Array[i+1]) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int calc_fib(int n) { | |
if (n <= 1) | |
return n; | |
return calc_fib(n - 1) + calc_fib(n - 2); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
long long get_pisano_period(long long m) { | |
long long a = 0, b = 1, c = a + b; | |
for (int i = 0; i < m * m; i++) { | |
c = (a + b) % m; | |
a = b; | |
b = c; | |
if (a == 0 && b == 1) return i + 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int get_fibonacci_last_digit(long long n) { | |
int first = 0; | |
int second = 1; | |
int res; | |
for (int i = 2; i <= n; i++) { | |
res = (first + second) % 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int gcd(int a, int b) { | |
int current_gcd = 1; | |
for (int d = 2; d <= a && d <= b; d++) { | |
if (a % d == 0 && b % d == 0) { | |
if (d > current_gcd) { | |
current_gcd = d; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int euclidGCD (long a, long b) { | |
if (b == 0) return a; | |
return euclidGCD(b, a%b); | |
} | |
long long lcm(long long a, long long b) { | |
return (a * b)/euclidGCD(a, b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int get_change(int n) { | |
int coins[] = {10, 5, 1}; | |
int min = 0; | |
for (int i = 0; n > 0; i++) { | |
min += n / coins[i]; | |
n %= coins[i]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
using std::vector; | |
long long min_dot_product(vector<int> a, vector<int> b) { | |
std::sort(a.begin(), a.end()); | |
std::sort(b.begin(), b.end(), std::greater<int>()); | |
long long result = 0; | |
for (int i = 0; i < a.size(); i++) { |
OlderNewer