Skip to content

Instantly share code, notes, and snippets.

View rurumimic's full-sized avatar
♟️
턴제코딩

rurumimic

♟️
턴제코딩
View GitHub Profile
@rurumimic
rurumimic / HeapSort.swift
Created September 14, 2018 13:33
Heap Sort
import Foundation
var A = [4, 10, 14, 7, 9, 3, 2, 8, 1, 16]
func left(_ i: Int) -> Int {
return i * 2 + 1
}
func right(_ i: Int) -> Int {
return i * 2 + 1 + 1
@rurumimic
rurumimic / Ascii.swift
Last active September 14, 2018 13:45
Ascii
extension String {
var ascii: Int {
return Int(unicodeScalars.first!.value)
}
}
extension Int {
var toString: String {
return String(UnicodeScalar(self)!)
}
}
@rurumimic
rurumimic / kakao2017-3.5.swift
Created September 14, 2018 13:47
2017 카카오 3차 5번 내 풀이
import Foundation
class Node {
var parent: Node?
var childrens: [Character:Node] = [:]
var isWord: Bool = false
var count: Int = 0
init(parent: Node?) {
self.parent = parent
}
@rurumimic
rurumimic / BinarySearch.swift
Created September 14, 2018 14:03
Binary Search
import Foundation
func binarySearch<T: Comparable>(_ A: [T], key: T, _low: Int = 0, _high: Int = 0) -> Int? {
var low = _low
var high = _high
if _high == 0 {
high = A.count
}
while low < high {
let mid = low + (high - low) / 2
@rurumimic
rurumimic / gcd & lcm.swift
Created September 15, 2018 04:31
GCD & LCM
import Foundation
func gcd(_ p: Int, _ q: Int) -> Int {
return q == 0 ? p : gcd(q, p % q)
}
func lcm(_ p: Int, _ q: Int) -> Int {
return p / gcd(p, q) * q
}
@rurumimic
rurumimic / Bit.swift
Created September 15, 2018 04:32
비트 놀이
import Foundation
let x = 20
print(x&(x-1)) // 오른쪽 비트 끄기
print(x|(x+1)) // 제일 오른쪽 0의 비트 켜기
print(x&(x+1)) // 뒤에 딸린 1들을 끄기
print(x|(x-1)) // 뒤에 딸린 0들을 켜기
print((~x)&(x+1)) // 제일 오른쪽 0만 켜고 다른 것 다 끄기
print((~x)|(x-1)) // 제일 오른쪽 1만 끄고 다른 것 다 켜기
print((~x)&(x-1)) // 뒤에 딸린 0들만 켜고 다른 것 다 끄기
@rurumimic
rurumimic / board.cpp
Created September 28, 2018 13:10
C++ Board
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
template <typename T>
struct Board {
int w;
int h;
@rurumimic
rurumimic / gcd&lcm.cpp
Created September 28, 2018 13:15
C++ gcd & lcm
#include <iostream>
using namespace std;
int gcd(int p, int q) {
return q == 0 ? p : gcd(q, p % q);
}
int lcm(int p, int q) {
return p / gcd(p, q) * q;
#include <iostream>
using namespace std;
struct node {
int key;
node *left;
node *right;
node *parent;
@rurumimic
rurumimic / binaryTree.cpp
Created September 28, 2018 13:19
Binary Tree
#include <iostream>
using namespace std;
struct node {
int key;
int size;
node *left;
node *right;