Skip to content

Instantly share code, notes, and snippets.

View ntcho's full-sized avatar
🚀
Ready

Nathan Cho ntcho

🚀
Ready
View GitHub Profile
@ntcho
ntcho / matrix_chain_multiplication.py
Created May 7, 2023 23:54
Matrix chain multiplication problem in Python
# Matrix Chain Multiplication Optimization
# size of the matrix in the matrix chain
# A_1 is a p[0] by p[1] matrix, A_2 is a p[1] by p[2] matrix
p = [10, 20, 12, 17, 22, 19, 50]
# length of the matrix chain + 1
matrix_size = len(p)
# initialize matrix with zeros
@ntcho
ntcho / git-merge-repos.md
Created October 9, 2017 15:48
Merging git repositories
// at the copying repo
// move the files into another folder to prevent merge conflicts
git add .
git commit -m "Project move in progress"

// on the destionation repo
// the name `temp` could be changed for anything else
// locations are like in the shell, but the `\` should be replaced to `/`
git remote add temp *location*
@ntcho
ntcho / git-merge-repos.md
Created October 9, 2017 15:48
Merging git repositories

// at the copying repo // move the files into another folder to prevent merge conflicts git add . git commit -m "Project move in progress"

// on the destionation repo // the name temp could be changed for anything else // locations are like in the shell, but the \ should be replaced to / git remote add temp location git fetch temp

@ntcho
ntcho / LoopPython.py
Last active April 22, 2017 14:26
Python Loops
for i in range(0, 6):
print i
j = 0
while j < 5:
print j
j += 1
k = 0
while True:
@ntcho
ntcho / LoopC++.cpp
Created April 10, 2017 00:38
C++ Loops
int main() {
int i = 0, j = 0, k = 0;
// for statement
for (i = 0; i < 5; i++) {
print(i);
}
// while statement
while (j < 5) {
print(j++);
@ntcho
ntcho / LoopJava.java
Last active April 10, 2017 00:18
Java loops
public static void main(String args[]) {
int i = 0, j = 0, k = 0;
// for statement
for (i = 0; i < 5; i++) {
print(i);
}
// while statement
while (j < 5) {
print(j++);
@ntcho
ntcho / gist:00cea0e703d7c9642e72821b05009cc2
Created March 27, 2017 03:22
python programmatic flow error message
Traceback (most recent call last):
File "FILENAME", line 12, in <module>
repeat_lyrics()
NameError: name 'repeat_lyrics' is not defined
Process finished with exit code 1
@ntcho
ntcho / programmatic-flow.py
Created March 20, 2017 02:57
Python's programmatic flow
def print_lyrics():
print "I'm a lumberjack, and I'm okay"
print "I sleep all night and I work all day"
# repeat_lyrics()
# return an error: "NameError: name 'repeat_lyrics' is not defined"
def repeat_lyrics():
@ntcho
ntcho / SwapFuncOverloading.cpp
Created March 16, 2017 10:35
Function Overloading
#include <iostream>
void swap(int *n1, int *n2);
void swap(char *n1, char *n2);
void swap(double *n1, double *n2);
int main() {
int num1 = 20, num2 = 30;
swap(&num1, &num2);
std::cout << num1 << ' ' << num2 << std::endl;