Skip to content

Instantly share code, notes, and snippets.

@bennett39
bennett39 / fizzbuzz.py
Created March 22, 2023 18:05
An implementation of fizzbuzz
def fizzbuzz(stop: int):
"""On multiples of 3, print 'fizz'
On multiples of 5, print 'buzz'
On multiples of both, print 'fizzbuzz'
For all other numbers, print the number
"""
result = []
for x in range(1, stop+1):
if x % 15 == 0:
result.append('fizzbuzz')
@bennett39
bennett39 / dice_distribution.py
Last active April 24, 2023 14:34
I was curious about the distribution of results for dice. So, I wrote a few lines of Python.
def dice_distribution(num_sides: int) -> dict[int, float]:
"""
Get the distribution of possible results of two thrown dice
"""
distribution = {}
for x in dice_generator(num_sides):
for y in dice_generator(num_sides):
value = x + y
distribution.setdefault(value, 0)
distribution[value] += 1
import csv
with open('cancel.csv') as f:
reader = csv.DictReader(f)
words = {}
for row in reader:
reason = row['Reason']
if reason == 'System cancelled - non payment':
continue
@bennett39
bennett39 / tree.py
Created March 6, 2024 18:26
Playing around with binary trees
from typing import Optional
from collections import deque
class Node:
def __init__(self, value: int):
self.value = value
self.left = None
self.right = None
@bennett39
bennett39 / ramp.py
Created August 6, 2024 14:58
Code for pulling bills from Ramp
import requests
import base64
from datetime import datetime
def get_access_token():
"""Get a client credentials token."""
endpoint = "https://api.ramp.com/developer/v1/token"
client_id = "<client_id>"
client_secret = "<client_secret>"