Skip to content

Instantly share code, notes, and snippets.

View silverprize's full-sized avatar
🤟

SilverPrize silverprize

🤟
  • Seoul, South Korea
View GitHub Profile
@silverprize
silverprize / HeapSort.scala
Created December 9, 2014 15:27
Heapsort with scala
object HeapSort {
def sort(source: Array[Int]): Unit = {
buildHeap(source)
lineUp(source)
}
private def buildHeap(source: Array[Int]): Unit = {
def moveUp(source: Array[Int], idx: Int): Unit = {
if (idx > 0) {
val pIdx = Math.round(idx * 0.5f) - 1
@silverprize
silverprize / MergeSort.scala
Created December 5, 2014 09:04
Mergesort with scala
object MergeSort {
def sort(source: Array[Int]): Unit = {
branch(source, 0, source.length)
}
private def sortAndMerge(source: Array[Int],
offset0: Int, len0: Int,
offset1: Int, len1: Int): Unit = {
val buffer = new Array[Int](len0 + len1)
@silverprize
silverprize / Base64.groovy
Last active August 29, 2015 14:10
base64 encoding
intToBase64 = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
]
def encode(InputStream is) {
int countByte = 2