Skip to content

Instantly share code, notes, and snippets.

@lavaboom
lavaboom / slot_utils.py
Last active July 15, 2019 18:33
[SlotSimUtils] A collection of utils function used in slot sim and probabilities calculation #python #slot #casino
def get_random_option_from_weight(options, weights):
'''
python 3.6 and later
'''
import random
return random.choices(options, weights)[0]
@lavaboom
lavaboom / vanilla-js-cheatsheet.md
Created February 7, 2018 22:49 — forked from thegitfather/vanilla-js-cheatsheet.md
Vanilla JavaScript Quick Reference / Cheatsheet
@lavaboom
lavaboom / binary_sum
Last active November 12, 2017 05:06
[CLRS 2.1.4] Binary sum #python
def binary_sum(a, b):
'''
Sum 2 lists of bits of length n. Result a list of length n+1
'''
result = []
carry = 0
for x in zip(reversed(a), reversed(b)):
c = (sum(x) + carry) % 2
carry = int((sum(x) + carry) / 2)
@lavaboom
lavaboom / prime_checker.py
Last active September 25, 2021 13:13
Prime checker #python #numbers
'''
From SO
Check for prime. Only need to iterate up to the square root of n because:
If n = a*b, its either a = b (each a sqrt of n) or a != b. If a != b,
either one of them must be less than the sqrt. Hence, only need to check up
to sqrt of n.
'''
import math
def is_prime(n):
if n % 2 == 0 and n > 2: