Skip to content

Instantly share code, notes, and snippets.

View Alfex4936's full-sized avatar
✏️
I may be slow to respond.

seok Alfex4936

✏️
I may be slow to respond.
View GitHub Profile
@Alfex4936
Alfex4936 / Quick.java
Created September 29, 2020 14:20
Quick Sort using Tail recursive, Hoare partition scheme, Insertion Sort in Java
package csw;
import java.util.Random;
public class Quick {
public static void main(String[] args) {
Random rd = new Random();
Double[] test = new Double[500_000];
@Alfex4936
Alfex4936 / compare.py
Created October 1, 2020 05:20
Python example of calculating comparison numbers of sorting algorithms
from bigO import bigO
class Comparator:
def __init__(self):
self.comparisons = 0
def compare(self, a, b):
self.comparisons += 1
if a < b:
@Alfex4936
Alfex4936 / MersenneTwister.py
Last active October 17, 2020 04:18
Mersenne Twister in Python
class MTP:
def __init__(self):
# Coefficients
self.a = 0x9908B0DF # 2567483615
self.b = 0x9D2C5680 # 2636928640
self.c = 0xEFC60000 # 4022730752
self.f = 1812433253
self.l = 18
self.m = 397
self.n = 624
@Alfex4936
Alfex4936 / rabin_karp.py
Created October 18, 2020 09:29
Rabin-Karp algorithm in Python
from fastcore.all import *
class Node:
def __init__(self, val, start=-1, end=-1):
store_attr()
def print(self):
print(f"{self.val}: index from {self.start} to {self.end}.")
@Alfex4936
Alfex4936 / fastcore_self.py
Created October 18, 2020 10:11
Python: fastcore Self usage
from fastcore.utils import Self, L
if __name__ == "__main__":
f = Self.sum()
x = L(1, 2, 3)
print(f(x))
f = Self.map(lambda a: a + 1)
x = L(1, 2, 3)
@Alfex4936
Alfex4936 / pyc_bubblesort.py
Created October 23, 2020 03:38
Python bubble sort interface using C module
static PyObject *python_bubblesort(PyObject *module, PyObject *arg)
{
assert(arg);
Py_INCREF(arg);
if (!PyList_CheckExact(arg))
{
PyErr_SetString(PyExc_ValueError, "Argument is not a list.");
goto except;
}
@Alfex4936
Alfex4936 / bubble.pyx
Created October 24, 2020 10:44
Bubble Sort using Cython
def bubbleSort(list array):
return bubbleSort_c(array)
cdef bubbleSort_c(list array):
cdef bint isSorted = False
cdef int count = 0
cdef Py_ssize_t i
cdef Py_ssize_t n = len(array) - 1
while not isSorted:
@Alfex4936
Alfex4936 / c#.cs
Last active November 8, 2020 03:22
programming languages that support one-line swapping.
// Tuples
int a = 1;
int b = 2;
(a, b) = (b, a);
@Alfex4936
Alfex4936 / pytorch-adabelief.ipynb
Created October 28, 2020 08:22
PyTorch Adabelief.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Alfex4936
Alfex4936 / lru.py
Created November 16, 2020 07:58
LRU Cache implementation in Python
class Node:
__slots__ = ("key", "val", "prev", "next")
def __init__(self, key, val):
self.key = key
self.val = val
self.prev = None
self.next = None