This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <vector> | |
#include <queue> | |
#include <algorithm> | |
#include <cstring> | |
#include <iostream> | |
using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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: ν½ κ°―μ. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
NewerOlder