Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import numpy as np
from math import log
import sys
sys.path.append('../')
@shogonir
shogonir / exam1.py
Created July 8, 2015 06:30
I tried "Five programming problems every Software Engineer should be able to solve in less than 1 hour" in Python.
#! /usr/bin/env python
# -*- coding:utf-8 -*-
num_list = range(10)
# use for roop
list_sum = 0
for num in num_list :
list_sum += num
print 'list_sum counted with for roop :', list_sum
@shogonir
shogonir / quick_sort.c
Created June 2, 2015 05:16
quick sort implemented with C
int pivot_index (int n, int *a) {
int i;
for (i=1; i<n; i++) {
if (a[i] != a[0]) {
// pivot exists
return a[i] > a[0] ? i : 0;
}
}
// pivot not exists
return -1;
@shogonir
shogonir / insertion_sort.c
Created June 2, 2015 05:13
insertion sort implemented with C
void insertion_sort (int n, int *a) {
int i, j, swap;
for (i=1; i<n; i++) {
j = i-1;
while (j>=0 && a[j]>a[j+1]) {
swap = a[j];
a[j] = a[j+1];
a[j+1] = swap;
j--;
}