Git clone without deep history make cloning faster when we only need the latest code.
First run
$ python3 pivot-pandas.py
date stock_code price
0 2018-08-27 001 10.0
1 2018-08-27 002 11.0
2 2018-08-27 003 12.0
3 2018-08-27 004 13.0
4 2018-08-26 001 14.0
5 2018-08-26 002 15.0
Given a 6 sided dice, how many number of throws are required to guarantee a 6 as output?
This solution is basically finding expectation over 1 roll, 2 rolls, 3 rolls ... and so on until infinite rolls of dice. Basically SUM( k * P(rolls=k)) for k = 1 to infinity. Now probability we get a 6 in exactly kth roll is defined as P(rolls=k) = q^(k-1) * p, where p is probability we get a 6 in kth roll, and q^(k-1) is probability we do not get a 6 in all k-1 rolls. I guess it still cannot guarantee that we will always get a 6, rather that if we roll on average of 6 times in a row, we will get definitely get a 6. Quite interesting problem indeed.
References:
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law. https://en.wikipedia.org/wiki/Hofstadter's_law
f(x) = g(x) + delta + lambda*f(x)
where
# find closest pair of points in 2d space in O(nlogn) | |
import sys | |
import math | |
def euclidean_distance(p1, p2): | |
x1, y1 = p1 | |
x2, y2 = p2 | |
return math.sqrt((x2-x1)**2 + (y2 - y1)**2) |
Create a disk file with random data
$ truncate -s 50G encrypted_backup.disk
Setup encryption for that device file
$ cryptsetup --verbose --verify-passphrase -s 512 luksFormat encrypted_backup.disk