Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
@pamelafox
pamelafox / recursive_approaches.py
Created March 19, 2021 02:01
Recursive problem solving approaches
# Recursion + number + return
def sum_digits(n):
"""
>>> sum_digits(1234)
10
"""
if n < 10:
return n
return n % 10 + sum_digits(n // 10)
class Tree:
"""A tree."""
def __init__(self, label, branches=[]):
self.label = label
for branch in branches:
assert isinstance(branch, Tree)
self.branches = list(branches)
def __repr__(self):
if self.branches:
@pamelafox
pamelafox / link_iter.py
Created March 15, 2021 01:42
link_iter.py
@pamelafox
pamelafox / warandpeace.py
Last active May 26, 2024 12:49
War and Peace Insertion Showdown
import timeit
class Link:
empty = ()
def __init__(self, first, rest=empty):
self.first = first
self.rest = rest
def insert_at_start(self, value):
import dis
def for_version():
y = 0
for x in [1, 2, 3]:
y += x * 2
def iter_version():
_gen_ = iter([1, 2, 3])
y = 0
@pamelafox
pamelafox / pairing.py
Last active January 12, 2021 23:54
Pairing aging distant pop stars
""" Check your work by running python -m doctest -v popstar.py """
def gen_popstar_name(last_name, street, last_food):
"""Your pop star name is your last name followed
by the name of the street your grew up on followed
by the last food you ate.
The only whitespace should be between each of the
three parts, and the name should be uppercase.
>>> gen_popstar_name("fox", "city lights", "bananas")
@pamelafox
pamelafox / fibonacci.html
Created September 17, 2020 22:03
Animated Fibonacci SVG
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Fibonacci (Animated)</title>
<style>
body {
background: #f3f3f3;
}
@pamelafox
pamelafox / astronauts.sql
Created March 20, 2020 18:24
NASA astronauts, 1959-Present
/* Source:
https://www.kaggle.com/nasa/astronaut-yearbook
*/
CREATE TABLE astronauts(
Name TEXT PRIMARY KEY,
Year INTEGER,
GroupNum INTEGER,
Status TEXT,
Birth_Date TEXT,
Birth_Place TEXT,
@pamelafox
pamelafox / nba_players.sql
Created March 20, 2020 18:17
NBA players of the week
/*
Source:
https://www.kaggle.com/jacobbaruch/nba-player-of-the-week
*/
CREATE TABLE players(
Player TEXT,
Team TEXT,
Conference TEXT,
Date TEXT,
Position TEXT,