Skip to content

Instantly share code, notes, and snippets.

View riceluxs1t's full-sized avatar
🏠
Working from home

Namgun Kim riceluxs1t

🏠
Working from home
View GitHub Profile
method Divide(x: nat, y: nat) returns (q: nat, r: nat)
requires y > 0;
ensures q * y + r == x && r >= 0 && r < y;
{
q := 0;
r := x;
while (r >= y)
{
r := r - y;
q := q + 1;
@riceluxs1t
riceluxs1t / random_pivot_dp.py
Created October 26, 2017 23:33
random pivot DP approach
dp = {}
# computes the probability
# that the ith smallest element and the jth smallest element are compared
# considering
# kth smallest, k + 1 th smallest element, ..., i th smallest .. j th smallest
# ... lth smallest element.
# using DP.
#
def solve(k, l, i, j):
# if this value has been computed already, simply return it.
42 22 True True
30 1 True True
34 1 True True
23 19 True True
24 18 True True
45 27 True True
128 36 True True
135 4 True True
102 54 True True
142 20 True True
@riceluxs1t
riceluxs1t / riverse
Last active February 28, 2017 03:40
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
import random
def mixUp(x, y):
child_x = random_child(x)
child_y = random_child(y)
num_rows =len(x)
num_cols = len(x[0])
variant = [[1,2,4,5,6],[7,8,10,11,12],[13,14,16,17,18],[19,20,22,23,24],[25,26,28,29,30]]
for a in variant:
row = a
next = row[1]
for i in row:
if next-i == 1:
if next == row[1]:
next = row[2]
elif next == row[2]:
variant = [[1,2,4,5,6],[7,8,10,11,12],[13,14,16,17,18],[19,20,22,23,24],[25,26,28,29,30]]
for a in variant:
row = a
next = row[1]
for i in row:
if next-i == 1:
if next == row[1]:
next = row[2]
elif next == row[2]:
func throw_dice (arr_weights) {
W <- sum(arr_weights)
T <- RANDOM(0, W) // sample uniformly from [0, W)
cumsum <- 0
FOR i in 0..n-1, DO {
IF T-cumsum <= arr_weigths[i], THEN
RETURN arr_weights[i]
# -*- coding:utf-8 -*-
import random
from collections import defaultdict
def weighted_choice(choices, n):
"""
n개의 에드네트워크 정보를 픽한다. 단 이미 선택된 에드네트워크는 고려 대상에서 제외된다 (sample without replacement).
힙 자료구조를 이용한다. O(nlogn)
:param choices: 에드네트워크 초이스 정보가 담긴 리스트. 각 초이스정보는 딕셔너리. 딕셔너리의 키는 weight, adnetwork id, api key.
:param n: 픽 갯수.
#include <iostream>
using namespace std;
char board[12][6];
int processed[12][6];
char dir[4][2] = {
{-1,0}, //up
{1,0}, //down
{0,1}, //right
{0,-1}, //left