❯ ls -alrt
total 0
drwxr-xr-x 152 hughbrown staff 4864 Jan 15 12:00 ..
drwxr-xr-x 9 hughbrown staff 288 Jan 15 12:00 .git
-rw-r--r-- 1 hughbrown staff 0 Jan 15 12:00 x644
-rwxr-xr-x 1 hughbrown staff 0 Jan 15 12:01 x755
-rw------- 1 hughbrown staff 0 Jan 15 12:01 x600
drwxr-xr-x 6 hughbrown staff 192 Jan 15 12:01 .
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
#!/usr/bin/env python3 | |
# This is a simulation of the results for the first problem given here: | |
# https://fdpinstitute.org/resources/FDP%203.0/2024-Q2/Limited%20Sample%20MC%20Questions%20Q2-2024.pdf | |
# | |
# The expected answer given by the FDP Institute is 0.84. This is incorrect, as this simulation shows. | |
# The problem is that FDP has used the Bayesian formula incorrectly. Instead of using a weighted average | |
# of outcomes as the prior probability, FDP uses only the P(potted|~Simon) as the prior. | |
from collections import Counter |
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
from itertools import cycle | |
def spiral(n): | |
matrix = [[0] * n for _ in range(n)] | |
x, y = 0, 0 | |
x0, y0, xn, yn = 0, 0, n, n | |
directions = cycle([ | |
(1, 0, (0, 0, 1, 0)), | |
(0, 1, (0, -1, 0, 0)), | |
(-1, 0, (0, 0, 0, -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
import math | |
import hashlib | |
from bitarray import bitarray | |
class BloomFilter: | |
def __init__(self, n_items, fp_prob): | |
''' | |
n_items : int | |
Number of items expected to be stored in bloom filter |
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
""" | |
You're given a list of elements. Each "element" has a unique id and 3 properties. | |
Two elements E1 and E2 are "similar" if they share any of their 3 properties. | |
Please write a function that takes a list of elements as input, and returns all "similar" groups of elements. | |
Example Input: [E1, E2, E3] | |
E1: (id1, p1, p2, p3) | |
E2: (id2, p1, p4, p5) | |
E3: (id3, p6, p7, p8) |
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
#!/usr/bin/env python3 | |
import sys | |
from collections import defaultdict | |
line = sys.stdin.readline() | |
n = int(line.split(' ')[0]) | |
d = defaultdict(list) | |
for line in sys.stdin.readlines(): | |
src, dst = [int(x) for x in line.split(' ')] | |
d[src].append(dst) |
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
use itertools::Itertools; | |
pub fn split_paragraphs(lines: &Vec<&str>) -> Vec<String> { | |
let mut paragraphs: Vec<String> = vec![]; | |
for (key, group) in &lines.into_iter().group_by(|x| !x.is_empty()) { | |
if key { | |
paragraphs.push(group.map(|s: &&str| *s).collect::<Vec<&str>>().join(" ")); | |
} | |
} | |
paragraphs |
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
------------------------------ 'create_raw_lookup': 0:00:00.051461 seconds | |
[((0, 9), 'a7874d04-3a7c-4ab2-85f3-52de785c87e1'), | |
((10, 19), 'bbf24bb0-e1fd-41f3-ba6a-a983fff7c675'), | |
((20, 29), 'fab7cd13-d273-41a1-b749-e73d22521a04'), | |
((30, 39), '8d688ab2-4df3-4787-b715-d5acf36f43a2'), | |
((40, 49), '81081dca-abf8-46e4-a45b-f25d4e6b4876')] | |
------------------------------ 'create_expanded_lookup': 0:00:00.014262 seconds | |
[(0, 'a7874d04-3a7c-4ab2-85f3-52de785c87e1'), | |
(1, 'a7874d04-3a7c-4ab2-85f3-52de785c87e1'), | |
(2, 'a7874d04-3a7c-4ab2-85f3-52de785c87e1'), |
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
#!/usr/bin/env python3 | |
from pprint import pprint | |
from random import randint | |
from datetime import datetime | |
from uuid import uuid4 | |
import pandas as pd | |
NUMS = 10000 |
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
#!/usr/bin/env python3 | |
from timeit import timeit | |
def naive(values, k): | |
for i, v1 in enumerate(values): | |
for v2 in values[i + 1:]: | |
if v1 + v2 == k: | |
return True | |
return False |