Skip to content

Instantly share code, notes, and snippets.

View TenType's full-sized avatar

Max Wen TenType

  • Carnegie Mellon University
  • Pittsburgh, PA
  • 14:26 (UTC -04:00)
View GitHub Profile
import math
import random
N = 200 # REPLACE ME
class Simulation:
def __init__(self, partition_size: int):
self.partition_size = partition_size
self.bits = [-1] * N # 0, 1, or -1 (unset)
@TenType
TenType / coin_flip_paradox.py
Created February 16, 2025 19:39
Program to simulate and calculate scores in the coin flip paradox: https://www.youtube.com/watch?v=IAiNqQi30-Y
import random
def flip_coin():
"""
True = Heads, False = Tails
"""
return bool(random.getrandbits(1))
def flip_until_sequence(seq):
@TenType
TenType / Game.java
Last active September 7, 2025 17:35
Chopsticks Project
package chopsticks;
/**
* Chopsticks hand game
*/
public class Game {
// There are two players in the game
private Player p1;
private Player p2;
@TenType
TenType / LogicTester.java
Created September 15, 2023 01:00
Tests boolean expressions for logical equivalence
class LogicTester {
public static void main(String[] args) {
testBool(false, false);
testBool(true, false);
testBool(false, true);
testBool(true, true);
}
public static void testBool(boolean a, boolean b) {
boolean original = !a || (a && b);
@TenType
TenType / math_problem_gen.py
Last active April 23, 2023 00:40
Prints random math problems
from argparse import ArgumentParser
from itertools import product, islice
from random import sample
def main():
parser = ArgumentParser()
parser.add_argument("-p", "--prompt", action="store_true", help="prompt the user instead of using default values")
args = parser.parse_args()
@TenType
TenType / main.py
Created December 29, 2022 04:24
Decrement the digits in the first substring of every text file in a directory
import os
for entry in os.scandir('files'):
with open(entry) as file:
lines = file.readlines()
for i, line in enumerate(lines):
substr = line.split()[0]
new_substr = ''.join(str(int(c) - 1) for c in substr)
lines[i] = f'{new_substr} {line.split()[1]}\n'
@TenType
TenType / tutorial.md
Created December 11, 2022 08:10
Convert YouTube Shorts to Video

Directions

Paste this code into a new bookmark:

javascript:window.location.href=window.location.href.replace(/shorts\/(.*)/,'watch?v=$1')

Click the bookmark whenever you are watching a YouTube short to convert it to a regular video!

Other Formats

URL Encoded

@TenType
TenType / bin_dist.py
Last active December 8, 2022 05:07
Binomial distribution calculator
"""
Calculate binomial distribution using the formula
P(k successes) = nCk * p^k * q^(n - k)
where
n = ? (number of trials)
p = ? (probability of success on a single trial)
q = 1 - p (probability of failure on a single trial)
"""
from math import comb
@TenType
TenType / wrapper.js
Created June 3, 2022 01:51
Wrap HTML elements easily using JavaScript/TypeScript!
function wrap(element, wrapper) {
element.parentNode.insertBefore(wrapper, element);
wrapper.appendChild(element);
}
@TenType
TenType / tutorial.md
Created February 24, 2022 02:43
Python's __repr__ in NodeJS (custom class logging)

The Problem

Consider the following piece of JavaScript code:

class User {
    username = 'bob';
    followers = [
        { username: 'foo', followers: [
            { username: 'bar', followers: [] },
            { username: 'baz', followers: [] },
            { username: 'qux', followers: [] },